Skip to content

Commit 044e069

Browse files
committed
Add docs
1 parent 6247bb3 commit 044e069

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# setReusableSandboxOptions
8+
9+
The **`setReusableSandboxOptions()`** function configures the reuse of the same underlying sandbox for multiple requests, which can improve performance by avoiding the overhead of initializing a new sandbox for each request.
10+
11+
## Syntax
12+
13+
```js
14+
setReusableSandboxOptions(options)
15+
```
16+
17+
### Parameters
18+
19+
- `options` _: Object_
20+
- The configuration options for the reusable sandbox.
21+
- `maxRequests` _: number_ (default: `1`, `0` means unlimited)
22+
- The maximum number of requests that can be handled by a single sandbox before it is recycled.
23+
- `betweenRequestTimeoutMs` _: number_ (default: not specified)
24+
- The amount of time in milliseconds to wait between requests before recycling the sandbox.
25+
- `maxMemoryMiB` _: number_ (default: no limit)
26+
- The maximum amount of memory in MiB that the sandbox can use before it is recycled.
27+
- `sandboxTimeoutMs` _: number_ (default: no timeout)
28+
- The maximum amount of time in milliseconds that a sandbox can be active before it is recycled.

integration-tests/js-compute/fixtures/app/src/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { routes } from './routes.js';
55
import { env } from 'fastly:env';
66
import { enableDebugLogging } from 'fastly:experimental';
7-
import { setReusableSandboxOptions } from 'fastly:experimental';
87

98
import './async-select.js';
109
import './btoa.js';
@@ -57,13 +56,6 @@ import './tee.js';
5756
import './timers.js';
5857
import './urlsearchparams.js';
5958

60-
setReusableSandboxOptions({
61-
maxRequests: 10000, // Default is 1, 0 means unlimited
62-
//betweenRequestTimeoutMs: 10000000, // 100ms, default is 0 (no timeout)
63-
//maxMemoryMiB: 128, // 128MiB, default is 0 (no limit)
64-
//sandboxTimeoutMs: 1, // 1000ms, default is 0 (no timeout)
65-
});
66-
6759
addEventListener('fetch', (event) => {
6860
event.respondWith(app(event));
6961
});

types/experimental.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,32 @@ declare module 'fastly:experimental' {
8484
* @param error
8585
*/
8686
export function mapAndLogError(error: Error | string): void;
87+
88+
export interface ReusableSandboxOptions {
89+
/**
90+
* The maximum number of requests to handle with a single sandbox instance before it is recycled.
91+
* Default is 1. A value of 0 means there is no maximum, and the sandbox may be reused indefinitely until it is recycled for another reason (e.g., timeout or memory limit).
92+
*/
93+
maxRequests?: number;
94+
/**
95+
* The maximum amount of time in milliseconds to wait for the next request before recycling the sandbox. Default is up to the platform and not specified.
96+
*/
97+
betweenRequestTimeoutMs?: number;
98+
/**
99+
* The maximum amount of memory in MiB that the sandbox is allowed to use. If the sandbox exceeds this limit, it will be recycled before handling the next request. Default is no limit.
100+
*/
101+
maxMemoryMiB?: number;
102+
/**
103+
* The maximum amount of time in milliseconds that a sandbox is allowed to run before it is recycled after handling the current request. Default is no timeout.
104+
*/
105+
sandboxTimeoutMs?: number;
106+
}
107+
/**
108+
* Configure reuse of the same underlying sandbox for multiple requests,
109+
* which can improve performance by avoiding the overhead of initializing a
110+
* new sandbox for each request.
111+
* @experimental
112+
* @param options - Configuration options for sandbox reuse
113+
*/
114+
export function setReusableSandboxOptions(options: ReusableSandboxOptions): void;
87115
}

0 commit comments

Comments
 (0)