Jan Dubsky
86ffb019e1
Use Go 1.19 atomics
2022-10-28 18:20:56 -05:00
Jan Dubsky
d970a39050
Use generational stack for idle connections
2022-10-28 18:20:56 -05:00
Jan Dubsky
3009dbab62
[pool] Increase test coverage
2022-10-28 18:20:56 -05:00
Jan Dubsky
89668fae42
[pool] Replace queue with stack
2022-10-28 18:20:56 -05:00
Jan Dubsky
30b91519a0
Code review changes
2022-10-28 18:20:56 -05:00
Jan Dubsky
11c9fbfb3c
Perform logarithmic number of steps in AcquireAllIdle
2022-10-28 18:20:56 -05:00
Jan Dubsky
2c35738882
Use circular queue for idle connections
2022-10-28 18:20:56 -05:00
Jan Dubsky
021588b93e
Use semaphore rather than conditional variable
2022-10-28 18:20:51 -05:00
Jan Dubsky
9df21ce1a1
Separate duplicate code to functions
2022-10-28 18:20:03 -05:00
Jan Dubsky
6214680aa8
Replace useless locking by atomic variable
2022-10-28 18:20:03 -05:00
Jan Dubsky
93a3f7de51
Fix goroutine leak
2022-10-28 18:20:03 -05:00
Jan Dubsky
4fbc609092
Add banchmarks with cancelled acquires
2022-10-28 18:20:03 -05:00
Jack Christensen
d344a18fdb
Add to the destructWG wait group while cond.L is locked
...
Otherwise, if many constructors are underway while the pool is closed it
is possible destructWG will get to 0 while the Wait in Close is underway
and then Add will be called again which is disallowed.
From the docs:
Note that calls with a positive delta that occur when the counter is
zero must happen before a Wait.
https://github.com/jackc/pgx/issues/1356
2022-10-27 20:46:47 -05:00
Jack Christensen
fdc2381cbe
Do not cancel resource construction when Acquire is canceled
...
https://github.com/jackc/pgx/issues/1287
https://github.com/jackc/pgx/issues/1259
2022-09-03 13:08:12 -05:00
Jack Christensen
b1aadee38e
NewPool takes Config
...
This allows for backwards compatible additions. No features are planned
but this would make it easier if they are added.
2022-09-03 11:45:07 -05:00
James Hartig
f63192c063
Fix race with background Acquire creation
2022-08-27 18:02:55 -05:00
James Hartig
da694536ff
Create resources in the background in Acquire
2022-08-27 07:47:02 -05:00
Jack Christensen
6b44286e08
Add Reset()
2022-07-30 12:12:56 -05:00
Jack Christensen
40069f25d6
Remove compat layer and use generics directly
...
Backwards compatibility is not required since moving to v2.
2022-07-30 11:26:33 -05:00
Столяров Владимир Алексеевич
4e95984946
Move main logic to package and use generics for API with backwards compatibility
2022-04-04 07:56:16 -05:00
Jack Christensen
ba6bef1563
TryAcquire does not overfill pool
2021-12-02 18:00:10 -06:00
Jack Christensen
69f945a21a
Merge doAcquire back into Acquire
2021-12-02 18:00:10 -06:00
Jack Christensen
021a5cc1a6
TryAcquire created resource in background instead of blocking
...
refs #14
2021-12-02 18:00:10 -06:00
Jack Christensen
4d33264d63
Do not leave pool lock after panic from nil context
...
refs #13
2021-11-13 17:39:29 -06:00
Alexander Staubo
69a4c02937
Fix several memory leaks caused by modifying a slice length without
...
removing the elements from the backing array.
2021-11-13 04:51:43 -06:00
A. Jensen
cac2b5a858
Add TryAcquire and ErrNotAvailable
...
Fixes https://github.com/jackc/puddle/issues/10
2021-09-20 20:16:07 -05:00
Dmitriy Matrenichev
aa0e8cd5bc
Fix deadlock in Pool.CreateResource
2021-09-11 02:15:45 +03:00
Evgeny Vanslov
513cb84ff5
Ensure that conditional variable is signaled if resource failed to create
2020-12-03 19:14:39 +00:00
Yaz Saito
dd3aa6a6bc
Update the phrasing of TotalResources.
2020-10-03 23:04:50 -07:00
Yaz Saito
a70fb082df
Clarify the meanings of Stats accessors
2020-09-28 07:53:01 -07:00
Jack Christensen
91d0159cc9
Fix crash when pool is closed when resource is being created
...
Also, restore 100% test coverage.
2020-08-20 21:58:10 -05:00
Jack Christensen
6d0ef02e90
Fix: Resource.Destroy removed self from pool after destructor complete
2020-08-20 21:56:47 -05:00
Jack Christensen
558756d6c4
Fix race condition when CreateResource is called concurrently with Close
...
WaitGroup.Add(1) cannot be called after WaitGroup.Wait().
2020-04-02 22:11:33 -05:00
Jack Christensen
7cc1dd1985
CreateResource checks if pool is closed before any action
2020-04-02 22:11:22 -05:00
Jack Christensen
69489dce36
AcquireAllIdle immediately returns nil if pool is closed
2020-04-02 22:10:53 -05:00
Jack Christensen
2cd0ce3f9b
Closing a closed pool is a no-op
2020-04-02 22:10:13 -05:00
Jack Christensen
cde4bcb7af
Initialize LastUsedNanotime on creation
2020-02-03 08:25:42 -06:00
Patrick Ellul
c42fada37e
CreateResource sets LastUsedNanotime so that Idle Time calculations are still valid
2020-02-03 15:56:07 +11:00
Patrick Ellul
4014e4825a
CreateResource constructs a new resource without acquiring it.
2020-02-03 11:14:49 +11:00
Jack Christensen
807afe48a8
Use runtime.nanotime for duration tracking plus related restructuring
...
runtime.nanotime is significantly faster than time.Now. Use it unless
build tags prevent usage of unsafe.
Change LastUsedTime to LastUsedNanotime as a time.Time is no longer
available.
Add IdleDuration to make it more convenient to get the time a resource
has been idle.
Rename ReleaseIdle to ReleaseUnused to better indicate it is releasing
the resource without using it rather than that it is releasing a
resource acquired with AcquireAllIdle.
Refactor tests of usage tracking to not be intermingled with
AcquireAllIdle tests.
2020-01-25 18:47:55 -06:00
Jack Christensen
e6e0e7fd81
Get last used time outside of pool mutex
...
Under heavy contention this slightly improves performance by spending
less time in the mutex.
2020-01-25 17:22:31 -06:00
Jack Christensen
6897b9f0cd
Merge branch 'last-used-time' of git://github.com/ellulpatrick/puddle into ellulpatrick-last-used-time
2020-01-25 17:06:35 -06:00
Patrick Ellul
6a68341f62
maintain lastIUsedTime so clients can use it as a factor in idle and health check logic
2020-01-25 21:41:34 +11:00
Michael Tharp
26cd25c14b
Fix deadlock race when acquire is cancelled
...
If the waiter goroutine completes before the section guarding
canceledAcquireCount has run, then there is a deadlock because there is
nothing that can unlock the mutex. Scheduling the second goroutine
ensures that one of the two can release the lock and keep things moving.
2019-12-16 21:58:42 +00:00
Jack Christensen
e4ced69a3a
Ensure maxSize > 0
2019-04-13 18:43:25 -05:00
Jack Christensen
0395a39c2d
Use int32 for pool sizes
2019-04-13 18:39:08 -05:00
Jack Christensen
fefda73679
Add documention
2018-12-26 17:17:25 -06:00
Jack Christensen
383709a0b4
Achieve 100% test coverage
2018-12-26 17:17:08 -06:00
Jack Christensen
33a5f62a2e
Add stress test and fix race it detected
2018-12-26 16:35:01 -06:00
Jack Christensen
ba34bdd8ef
Add Pool.AcquireAllIdle
2018-12-26 15:52:48 -06:00