x/time (gotip)
| Legend: | Passed | Failed | Running | Exception |
all: upgrade go directive to at least 1.26.0 [generated]
By now Go 1.27.0 has been released, and Go 1.25 is no longer supported
per the Go Release Policy (see https://go.dev/doc/devel/release#policy).
See https://go.dev/doc/godebug#go-126 for GODEBUG setting changes
relevant to Go 1.26.
For golang/go#69095.
[git-generate]
(cd . && go get go@1.26.0 && go mod tidy)
Change-Id: Ie2c46b72bed3fddb50af5e94bed4d4c617997f58
Reviewed-on: https://go-review.googlesource.com/c/time/+/817940
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
all: upgrade go directive to at least 1.25.0 [generated]
By now Go 1.26.0 has been released, and Go 1.24 is no longer supported
per the Go Release Policy (see https://go.dev/doc/devel/release#policy).
See go.dev/doc/godebug#go-125 for GODEBUG changes relevant to Go 1.25.
For golang/go#69095.
[git-generate]
(cd . && go get go@1.25.0 && go mod tidy)
Change-Id: I75c525c74a1576e2aea77780bd5a73437c69b8ad
Reviewed-on: https://go-review.googlesource.com/c/time/+/744520
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
rate: use time.Time.Equal instead of ==
According to the Time Type documentation, in most cases, it is better
to use Equal instead of ==
Change-Id: I201de68ee163a06cf9ed49f7b77a2de031dbdd95
Reviewed-on: https://go-review.googlesource.com/c/time/+/703175
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
all: upgrade go directive to at least 1.24.0 [generated]
By now Go 1.25.0 has been released, and Go 1.23 is no longer supported
per the Go Release Policy (see https://go.dev/doc/devel/release#policy).
For golang/go#69095.
[git-generate]
(cd . && go get go@1.24.0 && go mod tidy && go fix ./... && go mod edit -toolchain=none)
Change-Id: Ia825a8b8f8877f184dd89af70b85a9d3facbbf19
Reviewed-on: https://go-review.googlesource.com/c/time/+/695675
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
rate: skip time.Now call in Sometimes.Do unless necessary
Don't update Sometimes.last if Interval is not configured.
goos: darwin
goarch: arm64
pkg: golang.org/x/time/rate
│ /tmp/before.txt │ /tmp/after.txt │
│ sec/op │ sec/op vs base │
Sometimes/no-interval-8 14.81n ± 0% 11.96n ± 0% -19.25% (p=0.000 n=10)
Sometimes/with-interval-8 27.30n ± 2% 27.57n ± 2% ~ (p=0.780 n=10)
geomean 20.10n 18.15n -9.70%
goos: linux
goarch: arm64
pkg: golang.org/x/time/rate
│ /tmp/before-rpi.txt │ /tmp/after-rpi.txt │
│ sec/op │ sec/op vs base │
Sometimes/no-interval-4 89.72n ± 4% 77.03n ± 2% -14.15% (p=0.000 n=10)
Sometimes/with-interval-4 147.1n ± 0% 147.8n ± 3% +0.48% (p=0.005 n=10)
geomean 114.9n 106.7n -7.12%
Change-Id: Ie4a064625432b9628a1cc5686eca9f0b3b90fb7b
Reviewed-on: https://go-review.googlesource.com/c/time/+/561956
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
all: upgrade go directive to at least 1.23.0 [generated]
By now Go 1.24.0 has been released, and Go 1.22 is no longer supported
per the Go Release Policy (https://go.dev/doc/devel/release#policy).
For golang/go#69095.
[git-generate]
(cd . && go get go@1.23.0 && go mod tidy && go fix ./... && go mod edit -toolchain=none)
Change-Id: Iaeb32276091bcf93b9f9ccde96e2705fe6367860
Reviewed-on: https://go-review.googlesource.com/c/time/+/649718
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
rate: simplify function advance only returns new Tokens to caller
Change the advance method to stop returning the newT result,
because it is always the same as the t argument.
Change-Id: Ib04017715d9f38f4ef6b908cb3d3b09af01b50b7
GitHub-Last-Rev: 1bc7316b96ca2d8e94f64f30db74536fe2fbe58f
GitHub-Pull-Request: golang/time#24
Reviewed-on: https://go-review.googlesource.com/c/time/+/645995
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
rate: prevent overflows when calculating durationFromTokens
Currently, there is a conversion from float64 to int64 when returning the duration needed to accumulate the required number of tokens.
When limiters are set with low limits, i.e. 1e-10, the duration needed is greater than math.MaxInt64.
As per the language specifications, in these scenarios the outcome is implementation determined.
This results in overflows on `amd64`, resulting in no wait, effectively jamming the limiter open.
Here we add a check for this scenario, returning InfDuration if the desired duration is greater than math.MaxInt64.
Fixes golang/go#71154
Change-Id: I775aab80fcc8563a59aa399844a64ef70b9eb76a
Reviewed-on: https://go-review.googlesource.com/c/time/+/641336
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
rate: make function comment match function name
Change-Id: I603ca855eac736e90d2ba2bb7ce61981a4a91918
Reviewed-on: https://go-review.googlesource.com/c/time/+/638776
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
README: don't recommend go get
These days people will just import the packages and the go tool will
do the right thing. We don't need to explain it.
Add a pointer to the git repo, though.
For golang/go#62645
Change-Id: I87fbf5d50e75120052f56ed6d4ac9977056cde9f
Reviewed-on: https://go-review.googlesource.com/c/time/+/624235
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
x/time/rate: correctly handle 0 limits
Decrementing the burst in the reserveN method will frequently lead to us
setting the burst to 0 which makes the limiter mostly unusable.
This code was originally added in https://go.dev/cl/323429 to fix #39984
but the implementation introduced a different bug. To avoid regressing
to the behaviour described in #39984, pre-fill the limiter to the burst
value in the constructor.
Fixes #68541
Change-Id: Iab3b85d548a44fcb2d058336e5bbf11b19ea67b1
Reviewed-on: https://go-review.googlesource.com/c/time/+/600876
Reviewed-by: Sameer Ajmani <sameer@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Sameer Ajmani <sameer@golang.org>
LICENSE: update per Google Legal
Very minor tweaks:
- Remove (c) pseudosymbol.
- Remove "All Rights Reserved."
- Change "Google Inc." (no longer exists) to "Google LLC".
[git-generate]
echo '
,s/\(c\) //
,s/ All rights reserved.//
,s/Google Inc./Google LLC/
w
q
' | sam -d LICENSE
Change-Id: Iaff5a0b4df05a69b33e2aa63f42e2476c255952d
Reviewed-on: https://go-review.googlesource.com/c/time/+/598529
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
rate: add documentation on Limiter concurrent usage
Closes golang/go#17261
Change-Id: Ifeacc8df45fb59e7781ddcc35c2fde0aa80188eb
Reviewed-on: https://go-review.googlesource.com/c/time/+/530855
Auto-Submit: Sameer Ajmani <sameer@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Sameer Ajmani <sameer@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
all: add a go directive, set it to 1.18
Done with:
go get go@1.18 toolchain@none
go mod tidy
go fix ./...
Using go1.21.3.
Otherwise the module is considered to have an implicit go 1.16 line.
While here, drop the by-now-always-satisfied go1.7 build constraint.
For golang/go#60268.
Change-Id: Ie0216c6f22c5e25321042e1b7bdaa59f3c3ae843
Reviewed-on: https://go-review.googlesource.com/c/time/+/534243
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
rate: the state of the limiter should not be changed when the requests failed
In the following cases, the reserveN is a no-op, and the state of
the limiter should not be changed:
1. n exceeds the Limiter's burst size
2. maxFutureReserve is less than the waitDuration
Fixes golang/go#52584
Change-Id: I5f38afa5da696bc10178a4bd0640d92062a8b009
GitHub-Last-Rev: e408718f070679209aca64bfbc18e4297777c311
GitHub-Pull-Request: golang/time#22
Reviewed-on: https://go-review.googlesource.com/c/time/+/406154
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Sameer Ajmani <sameer@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
x/time/rate: add rate.Sometimes, which runs a function occasionally.
Modeled after sync.Once; intended to provide simple throttling
akin to the C++ log functions LOG_FIRST_N, LOG_EVERY_N, and
LOG_EVERY_N_SEC.
Originally authored by sameer@golang.org.
Fixes golang/go#54237
Change-Id: I7c6266cc780eb6dad30d310485de492f790dbcdb
Reviewed-on: https://go-review.googlesource.com/c/time/+/421915
Reviewed-by: Sameer Ajmani <sameer@golang.org>
rate: add TokenAt and Tokens methods to Limiter.
Rename "now" to "t" in rate functions.
Improve comments in package rate and its test.
Fixes golang/go#50035
Change-Id: Icd84ce85d31ee8298b0814492f0856e1953923c8
Reviewed-on: https://go-review.googlesource.com/c/time/+/423042
Run-TryBot: Sameer Ajmani <sameer@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
rate: use constant to avoid repeated definitions
Change-Id: I344cacbad7208d56c9760c890c436f68b326b865
GitHub-Last-Rev: e776f693031b99d348da756bd91959b23c1fa199
GitHub-Pull-Request: golang/time#23
Reviewed-on: https://go-review.googlesource.com/c/time/+/431558
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
A+C: delete AUTHORS and CONTRIBUTORS
In 2009, Google's open-source lawyers asked us to create the AUTHORS
file to define "The Go Authors", and the CONTRIBUTORS file was in
keeping with open source best practices of the time.
Re-reviewing our repos now in 2022, the open-source lawyers are
comfortable with source control history taking the place of the
AUTHORS file, and most open source projects no longer maintain
CONTRIBUTORS files.
To ease maintenance, remove AUTHORS and CONTRIBUTORS from all repos.
For #53961.
Change-Id: I170c128b06b6a9ef12ae3b447dcfa00ca8d4bae9
Reviewed-on: https://go-review.googlesource.com/c/time/+/418924
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
rate: use fake time for testing
Fixes golang/go#43055
Change-Id: I2c6836f2da06b8a25f95b6ad494503051efe56fd
Reviewed-on: https://go-review.googlesource.com/c/time/+/411314
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
all: gofmt
Gofmt to update doc comments to the new formatting.
For golang/go#51082.
Change-Id: Ib5c83cdade85433f805d1b9f3203f319932a8939
Reviewed-on: https://go-review.googlesource.com/c/time/+/399604
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
rate: extend maximum-delay slop to all platforms
I initially added some timing slop for specific platforms based on the
failures we had seen so far (and a theory explaining at least some of
those failures). But now we've seen overruns on other platforms too,
so perhaps we should use the same factors everywhere.
Fixes #43055 (I hope).
Change-Id: Ib6035b55acd9d17acc7ad78065abf5f1e3f9dfe7
Reviewed-on: https://go-review.googlesource.com/c/time/+/399535
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
rate: extend timing tolerances on Android and Plan9
Fixes #43055
Change-Id: I72a88ff9d031192911a90a607eaf0366575eb313
Reviewed-on: https://go-review.googlesource.com/c/time/+/387834
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
rate: allow for more timing slop in TestWaitSimple
The 'd' constant is intentionally set fairly long to allow for builder
jitter; however, dFromDuration previously hard-coded only 1ms of
downward timing slop.
That slop can be introduced due to time spent between the call to
WaitN in the previous runWait and the call to time.Now in the current
runWait, and empirically may be a bit larger than 1ms on certain
builders (especially the android-amd64-emu builders, which also have
more clock drift than many other platforms; see golang/go#42513).
In addition, on some BSD platforms the slop in the upward direction
may actually be longer than d no matter how generously d is set. That
appears to be a platform bug (see golang/go#50189).
This change adjusts dFromDuration to round to the nearest d instead of
biasing in one direction or the other, and allows an additional factor
of slop on the affected BSD platforms.
Fixes #44067
Change-Id: Id4c073bee545be2291ad98158d764e19db0160cb
Reviewed-on: https://go-review.googlesource.com/c/time/+/383175
Trust: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
x/time/rate: handle zero limit correctly
Fixes golang/go#39984
Change-Id: Iee82550fd6f141b22afcf96aea41ec2ff3e98e9a
Reviewed-on: https://go-review.googlesource.com/c/time/+/323429
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Carlos Amedee <carlos@golang.org>
rate: simplify code
When a long time has passed since a previous call to the rate limiter,
we can overflow when calculating how many new tokens are available.
To prevent that, we calculated a maximum elapsed amount.
When we hit maxElapsed, we ended up converting a duration into tokens
and then back. This operation was lossy, so we took pains to increase
the precision of the conversion in tokensFromDuration.
An easier fix is to avoid the round trip entirely.
We know the max number of new tokens we should ever have,
so we can cap it directly. And in fact we do cap it already.
Delete the extraneous code.
This lets us revert to the original, simpler tokensFromDuration.
While we're here, tweak durationFromTokens for clarity.
Updates #34861
Change-Id: I9a3b0fd848d772b314aecc43fa675631b8be7f2f
Reviewed-on: https://go-review.googlesource.com/c/time/+/336469
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Eric Lagergren <ericscottlagergren@gmail.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
rate: mark test helper functions
Change-Id: I1710a207fd191acfde37f745e0b9cb7cd263d81a
Reviewed-on: https://go-review.googlesource.com/c/time/+/326331
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
rate: remove redundant return statements
Change-Id: Ic8a2d466d570ec503c75c45d9a5a8741eacacd6f
Reviewed-on: https://go-review.googlesource.com/c/time/+/325610
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
rate: use time.Since instead of time.Now().Sub
Change-Id: I140abf9d9283edb7259c9aa13ee69f3ca33181e6
Reviewed-on: https://go-review.googlesource.com/c/time/+/325609
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).
Not strictly necessary but will avoid spurious changes
as files are edited.
Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild
Change-Id: Ie289a4e2e52e68b7a6515102fb12d386beeb7a72
Reviewed-on: https://go-review.googlesource.com/c/time/+/294375
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
README.md: add badge to pkg.go.dev
Change-Id: Ia7262e29ce9e1635a693d1f97b54e5d3671e55c2
Reviewed-on: https://go-review.googlesource.com/c/time/+/276015
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
add lock for getting burst
Burst can be modified in `func (lim *Limiter) SetBurst(newBurst int)`, so it should be protected in `func (lim *Limiter) Burst() int`.
Change-Id: Ife2a733b035067d34e3165d2b2636666fcf2ee1d
GitHub-Last-Rev: bc8e73110ffccf7e42325e34865b473bc4624c31
GitHub-Pull-Request: golang/time#9
Reviewed-on: https://go-review.googlesource.com/c/time/+/205020
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Run-TryBot: Sameer Ajmani <sameer@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
rate: fix documentation of Limiter.ReserveN()
Update documentation string to mention that the returned
Reservation's OK() method returns false if n exceeds the
Limiter's burst size.
Fixes golang/go#38434
Change-Id: Ic549100189caad2ae6cda8379bfd8fa04b02c415
Reviewed-on: https://go-review.googlesource.com/c/time/+/228357
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Add critical section to protect lim.limit
***Description***
Among 9 usages of lim.limit , 8 of them are protected by `lim.mu.Lock()`, but the one at line 226 is not protected. So I add a critical section to protect the read operation.
Among 8 usages of lim.limit that are protected, there are 2 usages at line 350 and 357 in function `lim.advance()`. They may seem to be unprotected at first glance, since `lim.mu.Lock()` doesn't appear in `lim.advance()`, but actually all three usages of `lim.advance()` are in critical section.
***How to trigger this bug***
I found this bug occasionally by my static checker, so I can only come up with a hypothesis to trigger it:
If one goroutine is calling `rate.WaitN()` and another goroutine is calling `rate.SetLimitAt()`, then the read operation in `rate.WaitN()` and the write operation in `rate.SetLimitAt()` will race.
***About my patch***
There are several ways to fix this bug, and I chose an efficient but not elegant one. Please let me know if you think other ways are better.
Change-Id: I229bc06a2caa483b9dfb0f4e682cfc144c5aa07c
GitHub-Last-Rev: 192792cf2c5d0d3e8d1ac1345ead38f6ab3c46bc
GitHub-Pull-Request: golang/time#7
Reviewed-on: https://go-review.googlesource.com/c/time/+/188898
Reviewed-by: Sameer Ajmani <sameer@golang.org>
rate: fix rounding error in tokensFromDuration
tokensFromDuration performs a unit conversion by multiplying the limit
by the duration in seconds.
Make tokensFromDuration perform conversion by unit-wise multiplication
of limit by seconds and nanoseconds, instead of the conversion to
time.(Duration).Seconds that truncated the nanoseconds.
Fixes golang/go#34861
Change-Id: I94d290d3e32a87541d1702f2b58180270e1a9e96
Reviewed-on: https://go-review.googlesource.com/c/time/+/200900
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
rate: Add SetBurst() to dynamically update burst size
This commit adds the ability to dynamically update
burst size.
Fixes golang/go#23575
Signed-off-by: Simarpreet Singh <simar@linux.com>
Change-Id: I40da9ffdb108dee6ad15efb8700e3ae60d1169d9
Reviewed-on: https://go-review.googlesource.com/c/time/+/184082
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Run-TryBot: Sameer Ajmani <sameer@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
all: add a go.mod file
This change adds a go.mod file to this repo, following the
requirements stated in bcmills's comment here:
https://golang.org/issue/28136#issuecomment-462971974. It's
important to note that we will not be
adding versions to the repo for now.
This change does not add a go.sum file because this repo has no
dependencies on other repos.
The change was generated by running "go mod init" and "go mod tidy" using Go
1.11.5 in the top-level directory of the repository.
Updates golang/go#28136
Change-Id: If06ef87228cd9c8520de9aa457a97947caaaf53f
Reviewed-on: https://go-review.googlesource.com/c/time/+/162824
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
rate: remove Go 1.6 support, use std context
This is part of the general cleanup effort now that App Engine
requires Go 1.9+.
Related: CL 145677, CL 148277, CL 145202, CL 143717, CL 146837.
Change-Id: I831415f7484acb823cf8ac20db05a4a001df4c35
Reviewed-on: https://go-review.googlesource.com/c/148417
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
rate: avoid creating timer in WaitN if delay is zero
name old time/op new time/op delta
AllowN-4 76.7ns ± 6% 76.6ns ± 3% ~ (p=0.897 n=10+10)
WaitNNoDelay-4 1.36µs ± 3% 0.10µs ± 1% -92.64% (p=0.000 n=10+9)
name old alloc/op new alloc/op delta
AllowN-4 0.00B 0.00B ~ (all equal)
WaitNNoDelay-4 208B ± 0% 0B -100.00% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
AllowN-4 0.00 0.00 ~ (all equal)
WaitNNoDelay-4 3.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
Change-Id: I83addc3b3f7b053d6eee637fe188e21ca9b39f11
GitHub-Last-Rev: 2284b8e7b14d2f54870ddb80a40e8cf24996cd1f
GitHub-Pull-Request: golang/time#5
Reviewed-on: https://go-review.googlesource.com/106461
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CONTRIBUTING.md: remove note about not accepting Pull Requests
Updates golang/go#24185
Change-Id: I54972e6370a1de467b36c58e69483d0b42350c88
Reviewed-on: https://go-review.googlesource.com/100697
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
README: add better links, Markdown
Move the README to README.md so Gerrit can render it; currently
Gerrit only renders files named exactly "README.md" (for example at
https://go.googlesource.com/go).
Add more links to the README explaining how to file issues,
how to submit code changes, where to download the code to and
how to get it. Hopefully this should help people who go to
https://go.googlesource.com/time or https://github.com/golang/time
figure out how to get started with development.
Change-Id: I10f544c0bf2d17b49c5c9c9b096ac7f4b61c7cd2
Reviewed-on: https://go-review.googlesource.com/49891
Reviewed-by: Kevin Burke <kev@inburke.com>
rate: restore Go 1.6 support
https://golang.org/cl/41194 updatd the x/time/rate package to use the
standard library's context package for golang/go#16745 but App Engine
is stuck 14 months in the past and can only run Go 1.6, which lacks
context.
This CL restores Go 1.6 support.
The Go build system stopped testing packages against Go 1.6 once Go
1.8 came out, so just disable the tests for Go 1.6 rather than jumping
through hoops to make them work.
Change-Id: I271dcd492dd0ca53961340d63b26facb5dbdf025
Reviewed-on: https://go-review.googlesource.com/41624
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Chris Broadfoot <cbro@golang.org>
rate: use standard library context package
Fixes golang/go#16745
Change-Id: I34f87a2ae570c2bb0ce9ccb72fc5be0d34266e49
Reviewed-on: https://go-review.googlesource.com/41194
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dan Peterson <dpiddy@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
rate: change doc for ReserveN to reflect its signature
Change-Id: I97299d5a90b4273f42cb992bcf05b3c4786a2ac7
Reviewed-on: https://go-review.googlesource.com/32239
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
rate: ignore burst in WaitN when rate limit is Inf
WaitN fails when the number of tokens requested exceeds the limiter's
burst size, even when the rate limit is Inf. The documented behavior is
that the burst size is ignored when the rate limit is Inf. Change WaitN
to conform with the documentation, and add tests.
Fixes golang/go#16854
Change-Id: I3ca0a8dac47641c76bed4258cd7010f0a704ff8c
Reviewed-on: https://go-review.googlesource.com/28610
Run-TryBot: Sameer Ajmani <sameer@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
rate: double reserveN perf by 2x
This commit increase the speed of reserveN by 2x by removing the defer
to unlock.
NOTE: I did an audit of the code between Lock and Unlock and did not see
anything that can panic causing the Unlock to averted.
benchmark old ns/op new ns/op delta
BenchmarkAllowN-4 290 143 -50.69%
benchmark old allocs new allocs delta
BenchmarkAllowN-4 0 0 +0.00%
benchmark old bytes new bytes delta
BenchmarkAllowN-4 0 0 +0.00%
Change-Id: I01c23f4998f5451ea8efedd02e744fb5a74eae0d
Reviewed-on: https://go-review.googlesource.com/29379
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
rate: skip TestLongRunningQPS on OpenBSD
time.Sleep is significantly oversleeping on OpenBSD, rendering this
test invalid. Skip until that's resolved.
Updates #14183.
Change-Id: Ib0b79d198a0600454c5f74383d9933a2c05ddd2f
Reviewed-on: https://go-review.googlesource.com/19171
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
x/time/rate: provides a rate limiter.
The rate limiter works with golang.org/x/net/context's cancelation
mechanism: the Wait method blocks until the limiter permits the
operation to proceed or the context is canceled (in which case the
requested rate allocation is remitted for use by other operations).
Co-author: Arkadi Pyuro <arkadi@google.com>
Change-Id: I841db4e61fd169ac119fdc43105a1e16ca97e0a2
Reviewed-on: https://go-review.googlesource.com/16672
Reviewed-by: Russ Cox <rsc@golang.org>
initial commit