You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m using Laravel Octane and noticed an interesting behavior. When Octane initially boots up, it establishes a single database connection, and all requests use this same connection. This lack of re-connection boosts endpoint speed. However, if a transaction is started in one endpoint, all subsequent database operations use that same connection and behave as if the transaction is also active for them.
This creates issues. If an error occurs in an endpoint that started a transaction and triggers a rollback, unrelated endpoints using the same connection also experience the rollback, leading to inconsistency in database records.
To prevent this, I enabled DisconnectFromDatabases::class, so now each request establishes its own connection. However, instead of creating a new connection for each request, I would prefer to use a connection pooling strategy. Ideally, the worker could initialize a pool of around 200 connections at boot, then assign an available connection to each request. Once the request is complete, the connection would be marked as available again. This way, I could avoid connection delays while maintaining transaction isolation.
Could anyone suggest how I might achieve this? Or is there an existing package that implements something like this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello everyone,
I’m using Laravel Octane and noticed an interesting behavior. When Octane initially boots up, it establishes a single database connection, and all requests use this same connection. This lack of re-connection boosts endpoint speed. However, if a transaction is started in one endpoint, all subsequent database operations use that same connection and behave as if the transaction is also active for them.
This creates issues. If an error occurs in an endpoint that started a transaction and triggers a rollback, unrelated endpoints using the same connection also experience the rollback, leading to inconsistency in database records.
To prevent this, I enabled DisconnectFromDatabases::class, so now each request establishes its own connection. However, instead of creating a new connection for each request, I would prefer to use a connection pooling strategy. Ideally, the worker could initialize a pool of around 200 connections at boot, then assign an available connection to each request. Once the request is complete, the connection would be marked as available again. This way, I could avoid connection delays while maintaining transaction isolation.
Could anyone suggest how I might achieve this? Or is there an existing package that implements something like this?
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions