Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share database connections between EventStore instances #198

Closed
slashdotdash opened this issue Apr 23, 2020 · 4 comments · Fixed by #216
Closed

Share database connections between EventStore instances #198

slashdotdash opened this issue Apr 23, 2020 · 4 comments · Fixed by #216

Comments

@slashdotdash
Copy link
Member

slashdotdash commented Apr 23, 2020

EventStore v1.1 included support for Postgres schemas (#182) and dynamic event stores (#184). These running instances will often share the same database connection settings, however they won't share database connections. Instead each started event store will start its own pool of database connections (user configurable) plus two other connections used for locking and subscriptions.

Sharing a pool of connections to the same database between event stores would reduce the total number of connections required.

One way this could be acheived is by specifying a connection_pool as an event store config option. By using the same name for multiple event stores we could share the pool of connections between instances.

config :my_app, MyApp.EventStore,
  serializer: EventStore.JsonSerializer,
  username: "postgres",
  password: "postgres",
  database: "eventstore",
  hostname: "localhost",
  pool_size: 1,
  connection_pool: :shared_example
@davydog187
Copy link

@slashdotdash how much effort do you think this ticket is? We are running into this issue following dynamic apps, and I'm getting nervous about hitting db connection limits.

@slashdotdash
Copy link
Member Author

@davydog187 It might be quite a small change required.

The top-level EventStore.Supervisor is responsible for starting the main Postgrex connection process which sets the process name based on the event store's name. If a new config option was supported (connection_pool is what I initially thought of) to determine the connection process' name it would allow the process to be reused by multiple event store instances.

One caveat is that a MonitoredServer process would need to be used to start the Postgrex connection as it is problematic having multiple supervisors attempting to supervise the same named process. An intermediary process is needed to ensure a supervisor can be shutdown cleanly. Multiple supervisors linked to the same child process causes issues (see #194 for an example).

Leave it with me and I will do some investigation as this is a feature I will need in the near future.

@davydog187
Copy link

Thank you for the quick update! I'm happy to help out as well

@slashdotdash
Copy link
Member Author

Done in #216.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants