Skip to content

Add Neo4j max_connection_pool_size and connection_acquisition_timeout in sample_config files - #958

Merged
sscargal merged 1 commit into
MemMachine:mainfrom
sscargal:bugfix/940
Jan 16, 2026
Merged

sscargal merged 1 commit into
MemMachine:mainfrom
sscargal:bugfix/940

Conversation

@sscargal

@sscargal sscargal commented Jan 16, 2026 •

Copy link
Copy Markdown
Contributor

Purpose of the change

This is part of the ongoing performance improvements. This PR exposes Neo4j max_connection_pool_size and connection_acquisition_timeout by adding them to the database_manager and sample config files. Users can tune the Neo4j connection pool size and timeout as we did for Postgres.

Description

  • max_connection_pool_size controls how many simultaneous connections the driver can keep open to a single Neo4j server (or per cluster member, depending on the driver). It should be increased when you see connection-acquisition timeouts under high concurrent load, and your Neo4j server and network have capacity for more connections, and decreased when the database is over-subscribed, or you want to limit its resource usage.

  • connection_acquisition_timeout controls how long a query waits for a free connection from the pool before failing with a client-side timeout error, and it only applies when the pool is already at its configured maximum size. It should be increased if you see sporadic timeouts during brief load spikes but do not want to grow the pool further, decreased (or set to fail fast) when you prefer immediate errors over waiting, or set to unlimited if you want the client to block until a connection is free.

Fixes/Closes

Relates to #940

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

  • Manual verification (list step-by-step instructions)

Using this client connection script, and executing it in the project root, where the configuration.yml is:

uv run python -c "
import asyncio
from memmachine.common.configuration import Configuration
from memmachine.common.resource_manager.database_manager import DatabaseManager

async def verify():
    config = Configuration.load_yml_file('./configuration.yml')
    manager = DatabaseManager(config.resources.databases)
    
    name = 'my_storage_id'
    driver = await manager.async_get_neo4j_driver(name)
    
    # max_connection_pool_size is in pool_config
    pool_size = driver._pool.pool_config.max_connection_pool_size
    
    # connection_acquisition_timeout is in workspace_config
    acq_timeout = driver._pool.workspace_config.connection_acquisition_timeout
    
    print(f'\n--- Neo4j Driver Configuration for [{name}] ---')
    print(f'Max Connection Pool Size: {pool_size}')
    print(f'Connection Acquisition Timeout: {acq_timeout}s')
    
    await driver.close()

asyncio.run(verify())
"

With no properties in configuration.yml, I get

--- Neo4j Driver Configuration for [my_storage_id] ---
Max Connection Pool Size: 100
Connection Acquisition Timeout: 30.0s

When I add the properties and set them to non-default values, then re-run the script above, I get the expected output

    my_storage_id:
      provider: neo4j
      config:
        uri: "bolt://neo4j:7687"
        username: neo4j
        password: neo4j_password
        max_connection_pool_size: 200
        connection_acquisition_timeout: 120.0
        range_index_creation_threshold: 10
        vector_index_creation_threshold: 10
--- Neo4j Driver Configuration for [my_storage_id] ---
Max Connection Pool Size: 200
Connection Acquisition Timeout: 120.0s

Checklist

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

Screenshots/Gifs

N/A

Further comments

We will test and validate this PR using load-test scripts before merging to confirm that the issue reported in #940 is resolved.

@sscargal
sscargal requested review from a team and Copilot January 16, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances Neo4j connection pool configuration by exposing max_connection_pool_size and connection_acquisition_timeout parameters, allowing users to tune connection pool behavior under high concurrent load similar to existing Postgres configuration options.

Changes:

  • Added two new optional fields to Neo4jConf for controlling connection pool size and acquisition timeout
  • Modified async_get_neo4j_driver to conditionally pass these parameters to the Neo4j driver
  • Updated sample configuration files to include the new parameters with their default values

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/memmachine/common/configuration/database_conf.py Added max_connection_pool_size and connection_acquisition_timeout fields to Neo4jConf class
src/memmachine/common/resource_manager/database_manager.py Refactored driver initialization to conditionally include new configuration parameters
sample_configs/episodic_memory_config.gpu.sample Added example configuration values for the new Neo4j pool parameters
sample_configs/episodic_memory_config.cpu.sample Added example configuration values for the new Neo4j pool parameters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sscargal sscargal added the performance Issues relating to MemMachine performance label Jan 16, 2026
… in sample_config files

Signed-off-by: Steve Scargall <[email protected]>
@sscargal
sscargal merged commit be2264b into MemMachine:main Jan 16, 2026
40 checks passed
@sscargal
sscargal deleted the bugfix/940 branch January 16, 2026 23:28
o-love pushed a commit that referenced this pull request Jan 23, 2026
… in sample_config files (#958)

Signed-off-by: Steve Scargall <[email protected]>
SarahScargall pushed a commit to SarahScargall/MemMachine that referenced this pull request Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Issues relating to MemMachine performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants