Skip to content

Commit 9c84a56

Browse files
authored
Merge pull request #1227 from permaweb/jfrain99/dryrun-cache-config
fix(cu): add config vars for dryrun cache aprams
2 parents 7a2c1f4 + 7fc4896 commit 9c84a56

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

servers/cu/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ There are a few environment variables that you can set. Besides
145145
- `DEFAULT_LOG_LEVEL`: the logging level to use (defaults to `debug`)
146146
- `LOG_CONFIG_PATH`: the path to the file used to dynamically set the logging level (see [here](#dynamically-change-the-log-level))
147147
- `HYDRATION_MODE_NONCE_LIMIT`: the maximum nonce difference for incoming dryruns vs their pending eval streams.
148+
- `DRY_RUN_DEFAULT_MAX_PROCESS_AGE`: the maximum age of process memory that is allowed
149+
to be retrieved from the dryrun cache.
150+
- `DRY_RUN_PROCESS_CACHE_TTL`: the TTL of the dryrun process memory cache.
148151
If a eval stream is more nonces behind than this limit, a 503 is returned.
149152

150153
## Tests

servers/cu/src/bootstrap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,9 @@ export const createApis = async (ctx) => {
529529
)
530530
),
531531
logger: dryRunLogger
532-
})
532+
}),
533+
DRY_RUN_DEFAULT_MAX_PROCESS_AGE: ctx.DRY_RUN_DEFAULT_MAX_PROCESS_AGE,
534+
DRY_RUN_PROCESS_CACHE_TTL: ctx.DRY_RUN_PROCESS_CACHE_TTL
533535
})
534536

535537
/**

servers/cu/src/config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ const CONFIG_ENVS = {
179179
CHECKPONT_VALIDATION_THRESH: process.env.CHECKPONT_VALIDATION_THRESH || 0.75,
180180
CHECKPONT_VALIDATION_RETRIES: process.env.CHECKPONT_VALIDATION_RETRIES || 5,
181181
IGNORE_LOCAL_CHECKPOINTS: process.env.IGNORE_LOCAL_CHECKPOINTS === 'true',
182-
HYDRATION_MODE_NONCE_LIMIT: process.env.HYDRATION_MODE_NONCE_LIMIT || 200
182+
HYDRATION_MODE_NONCE_LIMIT: process.env.HYDRATION_MODE_NONCE_LIMIT || 200,
183+
DRY_RUN_DEFAULT_MAX_PROCESS_AGE: process.env.DRY_RUN_DEFAULT_MAX_PROCESS_AGE || 100,
184+
DRY_RUN_PROCESS_CACHE_TTL: process.env.DRY_RUN_PROCESS_CACHE_TTL || 2000
183185
},
184186
production: {
185187
MODE,
@@ -238,7 +240,9 @@ const CONFIG_ENVS = {
238240
CHECKPONT_VALIDATION_THRESH: process.env.CHECKPONT_VALIDATION_THRESH || 0.75,
239241
CHECKPONT_VALIDATION_RETRIES: process.env.CHECKPONT_VALIDATION_RETRIES || 5,
240242
IGNORE_LOCAL_CHECKPOINTS: process.env.IGNORE_LOCAL_CHECKPOINTS === 'true',
241-
HYDRATION_MODE_NONCE_LIMIT: process.env.HYDRATION_MODE_NONCE_LIMIT || 200
243+
HYDRATION_MODE_NONCE_LIMIT: process.env.HYDRATION_MODE_NONCE_LIMIT || 200,
244+
DRY_RUN_DEFAULT_MAX_PROCESS_AGE: process.env.DRY_RUN_DEFAULT_MAX_PROCESS_AGE || 100,
245+
DRY_RUN_PROCESS_CACHE_TTL: process.env.DRY_RUN_PROCESS_CACHE_TTL || 2000
242246
}
243247
}
244248

servers/cu/src/domain/api/dryRun.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { loadModuleWith } from '../lib/loadModule.js'
99
import { mapFrom } from '../utils.js'
1010
import { readStateWith } from './readState.js'
1111

12-
const DEFAULT_MAX_PROCESS_AGE = 100
1312
/**
1413
* TODO: should this be an effect or shared util?
1514
* just keeping here for sake of locality for now
@@ -58,6 +57,8 @@ const TtlCache = ({ setTimeout, clearTimeout }) => {
5857
* @returns {ReadResult}
5958
*/
6059
export function dryRunWith (env) {
60+
const DRY_RUN_DEFAULT_MAX_PROCESS_AGE = env.DRY_RUN_DEFAULT_MAX_PROCESS_AGE
61+
const DRY_RUN_PROCESS_CACHE_TTL = env.DRY_RUN_PROCESS_CACHE_TTL
6162
const logger = env.logger
6263
const loadMessageMeta = loadMessageMetaWith(env)
6364
const loadModule = loadModuleWith(env)
@@ -131,7 +132,7 @@ export function dryRunWith (env) {
131132
* the overhead of maintaining the map, timers, for the specified
132133
* age
133134
*/
134-
readStateCache.set(res.id, cached, 2000)
135+
readStateCache.set(res.id, cached, DRY_RUN_PROCESS_CACHE_TTL)
135136
return res
136137
}),
137138
Resolved
@@ -157,7 +158,7 @@ export function dryRunWith (env) {
157158
return Resolved(ctx)
158159
}
159160

160-
return ({ processId, messageTxId, maxProcessAge = DEFAULT_MAX_PROCESS_AGE, dryRun }) => {
161+
return ({ processId, messageTxId, maxProcessAge = DRY_RUN_DEFAULT_MAX_PROCESS_AGE, dryRun }) => {
161162
return of({ processId, messageTxId })
162163
.chain(loadMessageCtx)
163164
.chain(ensureProcessLoaded({ maxProcessAge }))

servers/cu/src/domain/model.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,16 @@ export const domainConfigSchema = z.object({
253253
* will return a busy response.
254254
*
255255
*/
256-
HYDRATION_MODE_NONCE_LIMIT: positiveIntSchema
256+
HYDRATION_MODE_NONCE_LIMIT: positiveIntSchema,
257+
/**
258+
* The default maximum age of a process that may be
259+
* retrieved from the dry run cache.
260+
*/
261+
DRY_RUN_DEFAULT_MAX_PROCESS_AGE: positiveIntSchema,
262+
/**
263+
* The TTL of the dry run process cache in milliseconds.
264+
*/
265+
DRY_RUN_PROCESS_CACHE_TTL: positiveIntSchema
257266
})
258267

259268
export const bufferSchema = z.any().refine(buffer => {

0 commit comments

Comments
 (0)