summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/puddle
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/jackc/puddle')
-rw-r--r--vendor/github.com/jackc/puddle/v2/CHANGELOG.md5
-rw-r--r--vendor/github.com/jackc/puddle/v2/README.md2
-rw-r--r--vendor/github.com/jackc/puddle/v2/nanotime.go16
-rw-r--r--vendor/github.com/jackc/puddle/v2/nanotime_time.go13
-rw-r--r--vendor/github.com/jackc/puddle/v2/nanotime_unsafe.go12
-rw-r--r--vendor/github.com/jackc/puddle/v2/pool.go20
6 files changed, 39 insertions, 29 deletions
diff --git a/vendor/github.com/jackc/puddle/v2/CHANGELOG.md b/vendor/github.com/jackc/puddle/v2/CHANGELOG.md
index a15991c58..d0d202c74 100644
--- a/vendor/github.com/jackc/puddle/v2/CHANGELOG.md
+++ b/vendor/github.com/jackc/puddle/v2/CHANGELOG.md
@@ -1,3 +1,8 @@
+# 2.2.2 (September 10, 2024)
+
+* Add empty acquire time to stats (Maxim Ivanov)
+* Stop importing nanotime from runtime via linkname (maypok86)
+
# 2.2.1 (July 15, 2023)
* Fix: CreateResource cannot overflow pool. This changes documented behavior of CreateResource. Previously,
diff --git a/vendor/github.com/jackc/puddle/v2/README.md b/vendor/github.com/jackc/puddle/v2/README.md
index 0ad07ec43..fa82a9d46 100644
--- a/vendor/github.com/jackc/puddle/v2/README.md
+++ b/vendor/github.com/jackc/puddle/v2/README.md
@@ -1,4 +1,4 @@
-[![](https://godoc.org/github.com/jackc/puddle?status.svg)](https://godoc.org/github.com/jackc/puddle)
+[![Go Reference](https://pkg.go.dev/badge/github.com/jackc/puddle/v2.svg)](https://pkg.go.dev/github.com/jackc/puddle/v2)
![Build Status](https://github.com/jackc/puddle/actions/workflows/ci.yml/badge.svg)
# Puddle
diff --git a/vendor/github.com/jackc/puddle/v2/nanotime.go b/vendor/github.com/jackc/puddle/v2/nanotime.go
new file mode 100644
index 000000000..8a5351a0d
--- /dev/null
+++ b/vendor/github.com/jackc/puddle/v2/nanotime.go
@@ -0,0 +1,16 @@
+package puddle
+
+import "time"
+
+// nanotime returns the time in nanoseconds since process start.
+//
+// This approach, described at
+// https://github.com/golang/go/issues/61765#issuecomment-1672090302,
+// is fast, monotonic, and portable, and avoids the previous
+// dependence on runtime.nanotime using the (unsafe) linkname hack.
+// In particular, time.Since does less work than time.Now.
+func nanotime() int64 {
+ return time.Since(globalStart).Nanoseconds()
+}
+
+var globalStart = time.Now()
diff --git a/vendor/github.com/jackc/puddle/v2/nanotime_time.go b/vendor/github.com/jackc/puddle/v2/nanotime_time.go
deleted file mode 100644
index f8e759386..000000000
--- a/vendor/github.com/jackc/puddle/v2/nanotime_time.go
+++ /dev/null
@@ -1,13 +0,0 @@
-//go:build purego || appengine || js
-
-// This file contains the safe implementation of nanotime using time.Now().
-
-package puddle
-
-import (
- "time"
-)
-
-func nanotime() int64 {
- return time.Now().UnixNano()
-}
diff --git a/vendor/github.com/jackc/puddle/v2/nanotime_unsafe.go b/vendor/github.com/jackc/puddle/v2/nanotime_unsafe.go
deleted file mode 100644
index fc3b8a258..000000000
--- a/vendor/github.com/jackc/puddle/v2/nanotime_unsafe.go
+++ /dev/null
@@ -1,12 +0,0 @@
-//go:build !purego && !appengine && !js
-
-// This file contains the implementation of nanotime using runtime.nanotime.
-
-package puddle
-
-import "unsafe"
-
-var _ = unsafe.Sizeof(0)
-
-//go:linkname nanotime runtime.nanotime
-func nanotime() int64
diff --git a/vendor/github.com/jackc/puddle/v2/pool.go b/vendor/github.com/jackc/puddle/v2/pool.go
index c8edc0fb6..c411d2f6e 100644
--- a/vendor/github.com/jackc/puddle/v2/pool.go
+++ b/vendor/github.com/jackc/puddle/v2/pool.go
@@ -139,6 +139,7 @@ type Pool[T any] struct {
acquireCount int64
acquireDuration time.Duration
emptyAcquireCount int64
+ emptyAcquireWaitTime time.Duration
canceledAcquireCount atomic.Int64
resetCount int
@@ -154,7 +155,7 @@ type Config[T any] struct {
MaxSize int32
}
-// NewPool creates a new pool. Panics if maxSize is less than 1.
+// NewPool creates a new pool. Returns an error iff MaxSize is less than 1.
func NewPool[T any](config *Config[T]) (*Pool[T], error) {
if config.MaxSize < 1 {
return nil, errors.New("MaxSize must be >= 1")
@@ -202,6 +203,7 @@ type Stat struct {
acquireCount int64
acquireDuration time.Duration
emptyAcquireCount int64
+ emptyAcquireWaitTime time.Duration
canceledAcquireCount int64
}
@@ -251,6 +253,13 @@ func (s *Stat) EmptyAcquireCount() int64 {
return s.emptyAcquireCount
}
+// EmptyAcquireWaitTime returns the cumulative time waited for successful acquires
+// from the pool for a resource to be released or constructed because the pool was
+// empty.
+func (s *Stat) EmptyAcquireWaitTime() time.Duration {
+ return s.emptyAcquireWaitTime
+}
+
// CanceledAcquireCount returns the cumulative count of acquires from the pool
// that were canceled by a context.
func (s *Stat) CanceledAcquireCount() int64 {
@@ -266,6 +275,7 @@ func (p *Pool[T]) Stat() *Stat {
maxResources: p.maxSize,
acquireCount: p.acquireCount,
emptyAcquireCount: p.emptyAcquireCount,
+ emptyAcquireWaitTime: p.emptyAcquireWaitTime,
canceledAcquireCount: p.canceledAcquireCount.Load(),
acquireDuration: p.acquireDuration,
}
@@ -363,11 +373,13 @@ func (p *Pool[T]) acquire(ctx context.Context) (*Resource[T], error) {
// If a resource is available in the pool.
if res := p.tryAcquireIdleResource(); res != nil {
+ waitTime := time.Duration(nanotime() - startNano)
if waitedForLock {
p.emptyAcquireCount += 1
+ p.emptyAcquireWaitTime += waitTime
}
p.acquireCount += 1
- p.acquireDuration += time.Duration(nanotime() - startNano)
+ p.acquireDuration += waitTime
p.mux.Unlock()
return res, nil
}
@@ -391,7 +403,9 @@ func (p *Pool[T]) acquire(ctx context.Context) (*Resource[T], error) {
p.emptyAcquireCount += 1
p.acquireCount += 1
- p.acquireDuration += time.Duration(nanotime() - startNano)
+ waitTime := time.Duration(nanotime() - startNano)
+ p.acquireDuration += waitTime
+ p.emptyAcquireWaitTime += waitTime
return res, nil
}