Allow users to configure the Postgres pool_size and max_overflow property values to improve performance #917
+62
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose of the change
This is Part 2 of n of my performance investigation into MemMachine.
To help users tune the Postgres and Neo4j Databases to handle more load when using our Docker Compose environment, this PR:
Description
The out-of-the-box settings for Postgres and Neo4j are not 100% suitable for MemMachine, especially when we enable FastAPI workers to handle more inbound traffic - See #903. When we increase the number of workers and inbound connections, the Postgres connection pool is set to 5, but we need more.
Similarly, in Neo4j, indexing occurs only every 10,000 nodes. This causes significant ingestion delays and O(n) lookup times until the indexes are created, as Neo4j does full table scans for each new insertion.
PostgreSQL Connection Pool Properties
pool_sizesets the fixed number of persistent database connections maintained in the pool for reuse, minimizing the expensive overhead of creating new connections for each FastAPI request.max_overflowdefines the maximum number of temporary extra connections allowed beyondpool_sizeduring traffic spikes, enabling the pool to expand dynamically without rejecting requests.Why Configure for Load Testing
During load tests, high concurrency from multiple FastAPI worker processes can exhaust fixed pools, causing stalls as workers queue indefinitely for connections and reducing parallelism.
Adjustable
pool_sizeandmax_overflowensure workers acquire connections promptly under load, improving throughput and preventing bottlenecks without over-provisioning persistent resources.This setup scales efficiently for production ASGI apps like FastAPI, balancing performance with resource limits as observed in SQLAlchemy QueuePool behavior.
Neo4j Index Threshold Properties
range_index_creation_thresholddetermines the minimum number of distinct values required in a property before Neo4j automatically creates a range index during planning, optimizing queries on discrete numeric or temporal data.vector_index_creation_thresholdsets the minimum number of distinct vector embeddings needed for automatic vector index creation, enabling efficient similarity searches in graph embeddings workloads.Why Configure for Load Testing
Under high-concurrency load tests with FastAPI workers generating dynamic Cypher queries, unset thresholds can delay index creation or force full scans, stalling processes and limiting query parallelism.
Tuning these thresholds ensures automatic indexes form proactively for common access patterns, reducing planning latency and allowing workers to retrieve results faster without manual intervention.
This configuration boosts throughput in production Neo4j deployments by balancing automatic optimization with resource constraints, similar to connection pool tuning.
Fixes/Closes
Fixes #906
Type of change
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.
Test Results: [Attach logs, screenshots, or relevant output]
See #837 and #906 for details.
Checklist
Maintainer Checklist
Screenshots/Gifs
As above
Further comments
As above