Skip to content

perf(harness): batch journal segment reads from workspace stores - #3996

Draft
chcodex wants to merge 1 commit into
agentscope-ai:mainfrom
chcodex:perf/store-session-batch-read
Draft

chcodex wants to merge 1 commit into
agentscope-ai:mainfrom
chcodex:perf/store-session-batch-read

Conversation

@chcodex

@chcodex chcodex commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

JournalSessionLog.scan bulk-loads committed segments through AtomicSessionStorage.readAll (added in #3666). StoreSessionStorage, used by remote workspace stores such as JDBC/MySQL, Redis and MongoDB, did not override readAll, so it fell back to the default implementation and issued one BaseStore.get per commit segment. A journal with 2,658 segments therefore performed 2,658 JdbcStore.get calls; on remote MySQL that takes tens of seconds.

This PR adds an opt-in bulk-read capability to BaseStore and uses it from StoreSessionStorage, so replay costs a bounded number of store queries for supporting backends.

Closes #3995

Changes

  • New BulkReadableStore extends BaseStore capability interface declaring getAll(namespace, keys).
    • BaseStore itself stays source-compatible; existing implementations compile and keep working unchanged.
  • getAll implementations:
    • InMemoryStore — direct compound-key lookup.
    • generic and MySQL JdbcStore, PostgresBaseStore — one IN (...) query per 256-key chunk, reusing one connection across chunks.
    • MongoBaseStore — _id $in per 256-key chunk.
    • RedisStore — bounded 256-key HGETALL pipelines with explicit sync.
  • StoreSessionStorage.readAll:
    • single path → direct get;
    • multiple paths and store instanceof BulkReadableStore → one getAll call;
    • otherwise → the previous paged search fallback, continuing past short pages, reading still-missing paths individually, and falling back to per-key reads when search is unsupported.
  • RedisStore.search now also uses bounded HGETALL pipelines per page, so listPaths avoids one round-trip per key.
  • ControlPlaneBaseStore, CosBaseStore, OssBaseStore and the codingagent SqliteBaseStore remain plain BaseStore implementations and use the search fallback.

Semantics

  • Missing paths are absent from the result and do not throw.
  • version < 1 still throws SessionLogException.
  • Values are base64-decoded into byte[].
  • Duplicate paths are deduplicated.
  • AtomicSessionStorage interface semantics and event formats are unchanged.

Tests

  • StoreSessionStorageTest covers parity with per-path read, bulk reads, single-path reads, paged-search fallback, unsupported-search fallback, missing paths, duplicate paths, versions and unversioned objects.
  • BaseStoreContractTest, JdbcStoreH2Test, PostgresBaseStoreTest, MongoBaseStoreTest, new RedisStoreTest and new MySQL JdbcStoreTest cover the backend implementations.
mvn -o -T1C -pl agentscope-harness,agentscope-extensions/agentscope-extensions-jdbc,agentscope-extensions/agentscope-extensions-postgresql,agentscope-extensions/agentscope-extensions-mongodb,agentscope-extensions/agentscope-extensions-mysql,agentscope-extensions/agentscope-extensions-redis -am \
  -Dtest='StoreSessionStorageTest,BaseStoreContractTest,WorkspaceSessionLogStoreTest,JournalSessionLogTest,JdbcStoreH2Test,PostgresBaseStoreTest,MongoBaseStoreTest,MongoBaseStoreContractTest,JdbcStoreTest,RedisStoreTest' \
  -Dsurefire.failIfNoSpecifiedTests=false test

mvn -o -T1C -pl agentscope-harness,agentscope-extensions/agentscope-extensions-jdbc,agentscope-extensions/agentscope-extensions-postgresql,agentscope-extensions/agentscope-extensions-mongodb,agentscope-extensions/agentscope-extensions-mysql,agentscope-extensions/agentscope-extensions-redis,agentscope-extensions/agentscope-extensions-cos,agentscope-extensions/agentscope-extensions-oss,agentscope-extensions/agentscope-extensions-controlplane,agentscope-examples/agents/agentscope-codingagent -am -DskipTests package

Both pass, including spotless:check.

Performance

With a fake store adding 1 ms latency per call and 2,658 requested paths:

  • previous per-path fallback: 2,658 get calls, ~2,957 ms
  • bulk getAll: 0 get calls, 11 search/batch pages, ~44 ms

This is a simulated latency comparison, not a MySQL measurement; real gains depend on RTT and on how many non-requested objects the session namespace contains.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test for the affected modules)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (not applicable: no public behavior change for existing stores)
  • Code is ready for review

Merge order

Scope note: this PR only accelerates the readAll bulk path (used by full replay when after == 0). Incremental per-segment read acceleration is handled separately by #4051's listKeys and #4039's single-scan path.

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

StoreSessionStorage did not override AtomicSessionStorage.readAll, so JournalSessionLog.scan fell back to one BaseStore.get per commit segment on remote JDBC/Redis/Mongo stores. Add an opt-in BulkReadableStore capability with getAll implementations for in-memory, JDBC, MySQL, PostgreSQL, MongoDB and Redis stores, and use it from StoreSessionStorage. StoreSessionStorage reads a single path directly, uses getAll for multiple paths when supported, and otherwise keeps the paged search fallback with missing-path reads and per-key fallback when search is unsupported. Preserve read semantics and leave BaseStore source-compatible.

Refs agentscope-ai#3995

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: StoreSessionStorage does not override readAll, so journal replay issues one get per segment

3 participants