Skip to content

Commit 133af16

Browse files
committed
refactor: clean up
1 parent b3e4628 commit 133af16

File tree

2 files changed

+31
-29
lines changed
  • apify-api/openapi/components/schemas/actors
  • sources/platform/actors/development/actor_definition/dynamic_actor_memory

2 files changed

+31
-29
lines changed

apify-api/openapi/components/schemas/actors/ActorDefinition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ properties:
4848
example: get(input, 'startUrls.length', 1) * 1024
4949
- type: integer
5050
example: 1024
51-
description: Specifies the default amount of memory in megabytes to be used when the Actor is started. Can be an integer or a dynamic memory expression.
51+
description: Specifies the default amount of memory in megabytes to be used when the Actor is started. Can be an integer or a [dynamic memory expression](/platform/actors/development/actor-definition/dynamic-actor-memory).
5252
minMemoryMbytes:
5353
type: integer
5454
minimum: 256

sources/platform/actors/development/actor_definition/dynamic_actor_memory/index.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Dynamic Actor memory
3-
description: Learn how to automatically adjust your Actor's memory based on input size and run options, so you can optimize performance and reduce costs without manual configuration..
3+
description: Learn how to automatically adjust your Actor's memory based on input size and run options, so you can optimize performance and reduce costs without manual configuration.
44
slug: /actors/development/actor-definition/dynamic-actor-memory
55
---
66

@@ -16,8 +16,10 @@ This helps:
1616
- _Reduce costs_ for small runs (less memory when it’s not needed).
1717
- _Provide better user experience_, so users get optimal performance without having to manually configure memory.
1818

19-
:::info
20-
_Important_: The memory calculated by dynamic expression is used as the default memory for the run. Users can still override it manually for each run.
19+
:::info Manual override
20+
21+
The memory calculated by dynamic expression is used as the default memory for the run. Users can still override it manually for each run.
22+
2123
:::
2224

2325
---
@@ -49,46 +51,46 @@ You can define a dynamic memory expression in your `actor.json`:
4951

5052
---
5153

52-
### Writing Expressions
54+
### How to write expressions
5355

5456
Expressions are based on [MathJS](https://mathjs.org/), extended with custom helper function `get`.
5557

56-
#### Variable Access
58+
#### Access run input and options
5759

5860
You can access variables in two ways:
5961

6062
1. Direct property access
6163

62-
```js
63-
input.foo + 512
64-
runOptions.maxItems + 256
65-
```
64+
```js
65+
input.foo + 512
66+
runOptions.maxItems + 256
67+
```
6668

67-
1. Double-brace syntax
69+
2. Double-brace syntax
6870

69-
```js
70-
{{input.foo}}
71-
{{runOptions.maxItems}}
72-
```
71+
```js
72+
{{input.foo}}
73+
{{runOptions.maxItems}}
74+
```
7375

7476
_You can mix both styles._
7577

76-
#### Supported Operations
78+
#### Supported operations
7779

7880
- Arithmetic: `+`, `-`, `*`, `/`
7981
- Math functions: `min()`, `max()`, `ceil()`, `floor()`, `round()`, `log()`, `exp()`, `log10()`
8082
- Conditional logic:
8183

82-
```js
83-
condition ? valueIfTrue : valueIfFalse
84-
```
84+
```js
85+
condition ? valueIfTrue : valueIfFalse
86+
```
8587

8688
- Variable assignment:
8789

88-
```js
89-
memoryPerUrl = 64;
90-
get(input, 'startUrls') * memoryPerUrl
91-
```
90+
```js
91+
memoryPerUrl = 64;
92+
get(input, 'startUrls') * memoryPerUrl
93+
```
9294

9395
#### Custom `get()` function
9496

@@ -120,13 +122,13 @@ After evaluation:
120122

121123
1. The result is rounded up to the nearest power of two
122124

123-
- 900 → 1024 MB
124-
- 3,600 → 4096 MB
125+
- 900 → 1024 MB
126+
- 3,600 → 4096 MB
125127

126-
1. It is clamped to actor-defined min/max (`minMemoryMbytes` / `maxMemoryMbytes`).
127-
2. It is clamped to platform limits (128 MB to 32 GB).
128+
2. It is clamped to actor-defined min/max (`minMemoryMbytes` / `maxMemoryMbytes`).
129+
3. It is clamped to platform limits (128 MB to 32 GB).
128130

129-
:::info
131+
:::info Fallback value
130132
If the calculation results in an error, the Actor will start with a fixed default memory, which can be configured in the Actor's UI settings.
131133
:::
132134

@@ -162,7 +164,7 @@ urls * reviewsMultiplier * 128
162164

163165
#### Use npm package
164166

165-
You can use our [npm package](https://www.npmjs.com/package/@apify/actor-memory-expression) not only to calculate memory for your expression, but also to write unit tests and verify the behavior of your expressions locally.
167+
You can use the [actor-memory-expressions](https://www.npmjs.com/package/@apify/actor-memory-expression) npm package not only to calculate memory for your expression, but also to write unit tests and verify the behavior of your expressions locally.
166168

167169
```shell
168170
npm install @apify/actor-memory-expression

0 commit comments

Comments
 (0)