Commit graph

33 commits

Author SHA1 Message Date
Brian J. Cardiff
c106775ea9
Simplifications and performance improvements (#200)
* Add pool_concurrency_test manual spec

Add MT connection count without Mutex

* Drop checkout_some, simpler pool_prepared statement

* Make pool statement a struct

* Drop StringKeyCache mutex

The StringKeyCache is now only used inside a connection. It's assumed that connections are not used concurrently with multiple queries.

* Drop do_close in pool statements

* Add specs and update comment

* Fix typo
2023-12-08 19:06:41 -03:00
Brian J. Cardiff
9471b33ffe
Fix max_idle_pool_size race condition (#186)
* Add Fiber.yield to dummy driver to mimic real drivers IO

* Add manual load test file

* Fix race condition

* Drop unused code

* Less state, less bugs

* Update spec/manual/load_test.cr

Co-authored-by: Beta Ziliani <beta@manas.tech>

---------

Co-authored-by: Beta Ziliani <beta@manas.tech>
2023-07-31 11:04:18 -03:00
Jamie Gaskins
ce95cd2257
Decrement the inflight counter on ConnectionRefused (#184) 2023-07-10 10:55:35 -03:00
Brian J. Cardiff
f13846b133
Refactor connection factory (#181)
* Start moving out URI from ConnectionContext

Create connections with an initial context. Database will set itself as context after connection has been created

* Migrate to simpler/decoupled factory in driver

This allows more freedom on how the connection is created. It will no longer need to have an explicit reference to the connection URI

* Introduce DB::Connection::Options

Move prepared_statements out from ConnectionContext

* Delegate options parsing to driver

DRY parsing connection options for database

* Introduce DB::Pool::Options

* Rename Driver#connection_pool_options to pool_options

* Drop driver getter from database

* Drop uri getter from database

* Add public Database#initialize method

* Drop :nodoc: Database#initialize

* Pass spec helper explicitly (to access methods within each spec)

* Update docs

* Update src/db/pool.cr

Co-authored-by: Beta Ziliani <beta@manas.tech>

* Use ConnectionBuilder instead of procs

* Fix inferred type when there is a single concrete connection type

* Update src/db/driver.cr

Co-authored-by: Beta Ziliani <beta@manas.tech>

---------

Co-authored-by: Beta Ziliani <beta@manas.tech>
2023-06-22 22:03:08 -03:00
Brian J. Cardiff
da7494b5ba
Fix mt issues (#178) 2023-04-24 12:26:25 +02:00
Stephen von Takach
a25f33611c
feat(error): close resources on resource lost (#155) 2021-09-10 08:36:01 -03:00
Stephen von Takach
6dc3f2dd6f
fix(pool): returning closed resources to the pool (#154) 2021-09-06 19:02:43 -03:00
Brian J. Cardiff
284145138f
Bump required Crystal to 0.35.0 (#135)
In order to use logging we need 0.35.0
2020-09-29 10:35:14 -03:00
Jamie Gaskins
291b65b853
Allow DB::Pool to be used a generic connection pool (#131)
* Allow DB::Pool to be a generic connection pool

* Use fully qualified class name for consistency

Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>

* Wrap only the necessary code in an `ensure`

* Add spec for http client pool

* Fix ICE in crystal-sqlite3

Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>
2020-09-14 10:49:00 -03:00
Brian J. Cardiff
f4b298d3a5 Use select / timeout in Crystal 0.34 2020-04-02 12:34:27 -03:00
Brian J. Cardiff
afad416417 Handle multiple fibers waiting for more resources than available 2019-09-11 18:25:40 -03:00
Brian J. Cardiff
5c1c1ab910 Handle inflight connections and rework state sync 2019-09-11 18:25:36 -03:00
Brian J. Cardiff
9275b22a30 Add pool stats 2019-09-11 17:53:39 -03:00
Jack
51236495f6
doc update
typo fix
2018-07-21 02:01:55 -05:00
Brian J. Cardiff
839a7abb5e Fix typo in comment 2017-11-07 23:23:06 -03:00
Nick Franken
5d5b901da1 Update to crystal 0.22.0 (#50)
* `WeakRef#target` was renamed to `WeakRef#value`
2017-04-21 11:14:42 -03:00
Brian J. Cardiff
09b8997636 Add before_checkout/after_release callbacks for resources in pool (#36)
add auto_release to DB::Connection (default true on each pool checkout).
fixes #35.
2017-01-16 16:47:58 -03:00
Brian J. Cardiff
2ca60ba43f Add ConnectionRefused exception
* required to fix retry+connection initialization corner case.
2016-12-15 14:40:56 -03:00
Brian J. Cardiff
cd10dabba2 default max_pool_size to 0 = unlimited 2016-11-13 18:21:05 -03:00
Brian J. Cardiff
3a7c801ece allow new connections right away if pool can be increased 2016-10-22 19:14:18 -03:00
Brian J. Cardiff
a62c90d092 remove connection from pool if explicitly closed 2016-09-13 01:36:49 -03:00
Brian J. Cardiff
ea2a107069 allow releasing connections of the pool from pool_statements
remove old connections from PoolStatement::@connections either disposed or closed connections
2016-09-12 14:35:21 -03:00
Brian J. Cardiff
6745ea956f migrate to crystal 0.19
* select keyword hangs so Channel.select is used still
2016-09-04 20:11:50 -03:00
Brian J. Cardiff
d3606831f3 Use select to distinguish between timeout and resource availability 2016-09-02 17:27:22 -03:00
Brian J. Cardiff
47e7d826e8 Add connection retry logic to connection pool 2016-08-31 17:32:01 -03:00
Brian J. Cardiff
dbf7c94ef4 release references to resources in pool. 2016-08-31 14:45:32 -03:00
Brian J. Cardiff
75aa821f5f make Database return PoolStatement
create StatementMethods for common interface between Statement and PoolStatment.
2016-08-29 16:56:34 -03:00
Brian J. Cardiff
8d891a5a4e changes needed due to 3c91978d36
add posibility to inspect availability of a resource in a pool (testing only)
allow access to internal connection pool of db (testing only)
2016-08-29 13:14:47 -03:00
Brian J. Cardiff
bed461c01b allow connection initialization 2016-08-18 00:55:43 -03:00
Ary Borenszweig
1cce4685ff Make DB::Pool accept a block 2016-07-11 15:38:31 -03:00
Brian J. Cardiff
a2c22c16cf allow DB to use a connection pool.
allow Driver to parse connection pool options for extensibility.
fix waiting_resource counter after a timeout was generated.
2016-07-07 15:50:09 -03:00
Brian J. Cardiff
b8cabee956 surround waiting_resource counter with a mutex for future thread support. 2016-07-07 14:48:58 -03:00
Brian J. Cardiff
421996b952 resource pool implementation with
* max_pool_size
* initial_pool_size
* max_idle_pool_size
* checkout_timeout
configuration options
2016-07-05 15:21:39 -03:00