Skip to content

Commit e0090b1

Browse files
Mention k6/experimental/fs in open() (#1649)
* Mention `k6/experimental/fs` in `open()` * Port changes to `next` * Port changes to `v0.48`-`v0.51` * Small edits --------- Co-authored-by: Heitor Tashiro Sergent <[email protected]>
1 parent 11559e6 commit e0090b1

File tree

6 files changed

+66
-60
lines changed
  • docs/sources
    • next/javascript-api/init-context
    • v0.48.x/javascript-api/init-context
    • v0.49.x/javascript-api/init-context
    • v0.50.x/javascript-api/init-context
    • v0.51.x/javascript-api/init-context
    • v0.52.x/javascript-api/init-context

6 files changed

+66
-60
lines changed

docs/sources/next/javascript-api/init-context/open.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ description: 'Opens a file and reads all the contents into memory.'
99

1010
Opens a file, reading all its contents into memory for use in the script.
1111

12-
{{% admonition type="note" %}}
12+
{{< admonition type="caution" >}}
1313

14-
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
15-
16-
To reduce the memory consumption, we strongly advise the usage of [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray) for CSV, JSON and other files intended for script parametrization.
14+
`open()` can only be called from the [init context](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle#the-init-stage). This restriction is necessary to determine the local files needed to bundle when distributing the test across multiple nodes.
1715

18-
{{% /admonition %}}
16+
{{< /admonition >}}
1917

20-
{{% admonition type="caution" %}}
18+
{{< admonition type="note" >}}
2119

22-
This function can only be called from the init context (aka _init code_), code in the global context that is, outside of the main export default function { ... }.
20+
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
2321

24-
By restricting it to the init context, we can easily determine what local files are needed to run the test and thus what we need to bundle up when distributing the test to multiple nodes in a clustered/distributed test.
22+
To reduce the memory consumption, you can:
2523

26-
See the example further down on this page. For a more in-depth description, see [Test lifecycle](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle).
24+
- Use `open()` within a [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray), which shares the allocated file memory between VUs.
25+
- Use [open() from the `k6/experimental/fs`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/fs/) module. It provides a memory-efficient way to handle file interactions in your test script and can read files in small chunks.
2726

28-
{{% /admonition %}}
27+
{{< /admonition >}}
2928

3029
| Parameter | Type | Description |
3130
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -38,6 +37,8 @@ See the example further down on this page. For a more in-depth description, see
3837
| -------------------- | ----------------------------------------------------------------------------------------------- |
3938
| string / ArrayBuffer | The contents of the file, returned as string or ArrayBuffer (if `b` was specified as the mode). |
4039

40+
### Examples
41+
4142
{{< code >}}
4243

4344
```json

docs/sources/v0.48.x/javascript-api/init-context/open.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ description: 'Opens a file and reads all the contents into memory.'
99

1010
Opens a file, reading all its contents into memory for use in the script.
1111

12-
{{% admonition type="note" %}}
12+
{{< admonition type="caution" >}}
1313

14-
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
15-
16-
To reduce the memory consumption, we strongly advise the usage of [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray) for CSV, JSON and other files intended for script parametrization.
14+
`open()` can only be called from the [init context](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle#the-init-stage). This restriction is necessary to determine the local files needed to bundle when distributing the test across multiple nodes.
1715

18-
{{% /admonition %}}
16+
{{< /admonition >}}
1917

20-
{{% admonition type="caution" %}}
18+
{{< admonition type="note" >}}
2119

22-
This function can only be called from the init context (aka _init code_), code in the global context that is, outside of the main export default function { ... }.
20+
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
2321

24-
By restricting it to the init context, we can easily determine what local files are needed to run the test and thus what we need to bundle up when distributing the test to multiple nodes in a clustered/distributed test.
22+
To reduce the memory consumption, you can:
2523

26-
See the example further down on this page. For a more in-depth description, see [Test lifecycle](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle).
24+
- Use `open()` within a [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray), which shares the allocated file memory between VUs.
25+
- Use [open() from the `k6/experimental/fs`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/fs/) module. It provides a memory-efficient way to handle file interactions in your test script and can read files in small chunks.
2726

28-
{{% /admonition %}}
27+
{{< /admonition >}}
2928

3029
| Parameter | Type | Description |
3130
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -38,6 +37,8 @@ See the example further down on this page. For a more in-depth description, see
3837
| -------------------- | ----------------------------------------------------------------------------------------------- |
3938
| string / ArrayBuffer | The contents of the file, returned as string or ArrayBuffer (if `b` was specified as the mode). |
4039

40+
### Examples
41+
4142
{{< code >}}
4243

4344
```json

docs/sources/v0.49.x/javascript-api/init-context/open.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ description: 'Opens a file and reads all the contents into memory.'
99

1010
Opens a file, reading all its contents into memory for use in the script.
1111

12-
{{% admonition type="note" %}}
12+
{{< admonition type="caution" >}}
1313

14-
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
15-
16-
To reduce the memory consumption, we strongly advise the usage of [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray) for CSV, JSON and other files intended for script parametrization.
14+
`open()` can only be called from the [init context](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle#the-init-stage). This restriction is necessary to determine the local files needed to bundle when distributing the test across multiple nodes.
1715

18-
{{% /admonition %}}
16+
{{< /admonition >}}
1917

20-
{{% admonition type="caution" %}}
18+
{{< admonition type="note" >}}
2119

22-
This function can only be called from the init context (aka _init code_), code in the global context that is, outside of the main export default function { ... }.
20+
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
2321

24-
By restricting it to the init context, we can easily determine what local files are needed to run the test and thus what we need to bundle up when distributing the test to multiple nodes in a clustered/distributed test.
22+
To reduce the memory consumption, you can:
2523

26-
See the example further down on this page. For a more in-depth description, see [Test lifecycle](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle).
24+
- Use `open()` within a [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray), which shares the allocated file memory between VUs.
25+
- Use [open() from the `k6/experimental/fs`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/fs/) module. It provides a memory-efficient way to handle file interactions in your test script and can read files in small chunks.
2726

28-
{{% /admonition %}}
27+
{{< /admonition >}}
2928

3029
| Parameter | Type | Description |
3130
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -38,6 +37,8 @@ See the example further down on this page. For a more in-depth description, see
3837
| -------------------- | ----------------------------------------------------------------------------------------------- |
3938
| string / ArrayBuffer | The contents of the file, returned as string or ArrayBuffer (if `b` was specified as the mode). |
4039

40+
### Examples
41+
4142
{{< code >}}
4243

4344
```json

docs/sources/v0.50.x/javascript-api/init-context/open.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ description: 'Opens a file and reads all the contents into memory.'
99

1010
Opens a file, reading all its contents into memory for use in the script.
1111

12-
{{% admonition type="note" %}}
12+
{{< admonition type="caution" >}}
1313

14-
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
15-
16-
To reduce the memory consumption, we strongly advise the usage of [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray) for CSV, JSON and other files intended for script parametrization.
14+
`open()` can only be called from the [init context](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle#the-init-stage). This restriction is necessary to determine the local files needed to bundle when distributing the test across multiple nodes.
1715

18-
{{% /admonition %}}
16+
{{< /admonition >}}
1917

20-
{{% admonition type="caution" %}}
18+
{{< admonition type="note" >}}
2119

22-
This function can only be called from the init context (aka _init code_), code in the global context that is, outside of the main export default function { ... }.
20+
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
2321

24-
By restricting it to the init context, we can easily determine what local files are needed to run the test and thus what we need to bundle up when distributing the test to multiple nodes in a clustered/distributed test.
22+
To reduce the memory consumption, you can:
2523

26-
See the example further down on this page. For a more in-depth description, see [Test lifecycle](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle).
24+
- Use `open()` within a [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray), which shares the allocated file memory between VUs.
25+
- Use [open() from the `k6/experimental/fs`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/fs/) module. It provides a memory-efficient way to handle file interactions in your test script and can read files in small chunks.
2726

28-
{{% /admonition %}}
27+
{{< /admonition >}}
2928

3029
| Parameter | Type | Description |
3130
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -38,6 +37,8 @@ See the example further down on this page. For a more in-depth description, see
3837
| -------------------- | ----------------------------------------------------------------------------------------------- |
3938
| string / ArrayBuffer | The contents of the file, returned as string or ArrayBuffer (if `b` was specified as the mode). |
4039

40+
### Examples
41+
4142
{{< code >}}
4243

4344
```json

docs/sources/v0.51.x/javascript-api/init-context/open.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ description: 'Opens a file and reads all the contents into memory.'
99

1010
Opens a file, reading all its contents into memory for use in the script.
1111

12-
{{% admonition type="note" %}}
12+
{{< admonition type="caution" >}}
1313

14-
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
15-
16-
To reduce the memory consumption, we strongly advise the usage of [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray) for CSV, JSON and other files intended for script parametrization.
14+
`open()` can only be called from the [init context](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle#the-init-stage). This restriction is necessary to determine the local files needed to bundle when distributing the test across multiple nodes.
1715

18-
{{% /admonition %}}
16+
{{< /admonition >}}
1917

20-
{{% admonition type="caution" %}}
18+
{{< admonition type="note" >}}
2119

22-
This function can only be called from the init context (aka _init code_), code in the global context that is, outside of the main export default function { ... }.
20+
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
2321

24-
By restricting it to the init context, we can easily determine what local files are needed to run the test and thus what we need to bundle up when distributing the test to multiple nodes in a clustered/distributed test.
22+
To reduce the memory consumption, you can:
2523

26-
See the example further down on this page. For a more in-depth description, see [Test lifecycle](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle).
24+
- Use `open()` within a [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray), which shares the allocated file memory between VUs.
25+
- Use [open() from the `k6/experimental/fs`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/fs/) module. It provides a memory-efficient way to handle file interactions in your test script and can read files in small chunks.
2726

28-
{{% /admonition %}}
27+
{{< /admonition >}}
2928

3029
| Parameter | Type | Description |
3130
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -38,6 +37,8 @@ See the example further down on this page. For a more in-depth description, see
3837
| -------------------- | ----------------------------------------------------------------------------------------------- |
3938
| string / ArrayBuffer | The contents of the file, returned as string or ArrayBuffer (if `b` was specified as the mode). |
4039

40+
### Examples
41+
4142
{{< code >}}
4243

4344
```json

docs/sources/v0.52.x/javascript-api/init-context/open.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ description: 'Opens a file and reads all the contents into memory.'
99

1010
Opens a file, reading all its contents into memory for use in the script.
1111

12-
{{% admonition type="note" %}}
12+
{{< admonition type="caution" >}}
1313

14-
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
15-
16-
To reduce the memory consumption, we strongly advise the usage of [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray) for CSV, JSON and other files intended for script parametrization.
14+
`open()` can only be called from the [init context](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle#the-init-stage). This restriction is necessary to determine the local files needed to bundle when distributing the test across multiple nodes.
1715

18-
{{% /admonition %}}
16+
{{< /admonition >}}
1917

20-
{{% admonition type="caution" %}}
18+
{{< admonition type="note" >}}
2119

22-
This function can only be called from the init context (aka _init code_), code in the global context that is, outside of the main export default function { ... }.
20+
`open()` often consumes a large amount of memory because every VU keeps a separate copy of the file in memory.
2321

24-
By restricting it to the init context, we can easily determine what local files are needed to run the test and thus what we need to bundle up when distributing the test to multiple nodes in a clustered/distributed test.
22+
To reduce the memory consumption, you can:
2523

26-
See the example further down on this page. For a more in-depth description, see [Test lifecycle](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-lifecycle).
24+
- Use `open()` within a [SharedArray](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-data/sharedarray), which shares the allocated file memory between VUs.
25+
- Use [open() from the `k6/experimental/fs`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/fs/) module. It provides a memory-efficient way to handle file interactions in your test script and can read files in small chunks.
2726

28-
{{% /admonition %}}
27+
{{< /admonition >}}
2928

3029
| Parameter | Type | Description |
3130
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -38,6 +37,8 @@ See the example further down on this page. For a more in-depth description, see
3837
| -------------------- | ----------------------------------------------------------------------------------------------- |
3938
| string / ArrayBuffer | The contents of the file, returned as string or ArrayBuffer (if `b` was specified as the mode). |
4039

40+
### Examples
41+
4142
{{< code >}}
4243

4344
```json

0 commit comments

Comments
 (0)