-
Notifications
You must be signed in to change notification settings - Fork 4
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calculating percentile is expensive #136
Comments
import random
import statistics
def one(data):
nine_nine = statistics.quantiles(data, n=100)[98]
return nine_nine
def two(data):
x = sorted(data)
index = int( (99/100) * len(x) )
nine_nine = x[index]
return nine_nine
data = range(1000)
one(data) # 989.99
two(data) # 990
def get_data():
data = []
for i in range(10_000):
a = random.randint(1, 1000 + i )
data.append(a)
return data
data = get_data()
one(data) # 9508.96
two(data) # 9509 |
komuw
added a commit
that referenced
this issue
Sep 26, 2022
What: - Simplify loadshedding implementation Why: - Fixes: #136 go test -run=XXXX -bench=BenchmarkLoadShedder -count=1 github.com/komuw/ong/middleware benchstat old.txt new.txt name old time/op new time/op delta LoadShedder-8 5.13s ± 9% 5.04s ± 7% ~ (p=0.409 n=20+18) name old alloc/op new alloc/op delta LoadShedder-8 297kB ± 1% 61kB ± 1% -79.55% (p=0.000 n=20+16) name old allocs/op new allocs/op delta LoadShedder-8 1.73k ± 1% 0.91k ± 1% -47.41% (p=0.000 n=20+16)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The way we calculate percentile is expensive;
ong/middleware/loadshed.go
Lines 142 to 171 in 1c6a5fc
currently they consume 9.04MB and 80ms as measured by the
BenchmarkAllMiddlewaresbenchmark.
I'm making the assertion that the alternative will be faster. And since this are just statistics; not that inaccurate for our purposes.
The text was updated successfully, but these errors were encountered: