Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
3d1705bd
Unverified
Commit
3d1705bd
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
The tool I used to help validate the solution.
parent
231f2f94
No related branches found
No related tags found
1 merge request
!61
Fix intermittent "Database is locked" errors
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc/load-test.py
+104
-0
104 additions, 0 deletions
misc/load-test.py
with
104 additions
and
0 deletions
misc/load-test.py
0 → 100755
+
104
−
0
View file @
3d1705bd
#! /usr/bin/env nix-shell
#! nix-shell -i python -p "python.withPackages (ps: [ ps.treq ])"
# Apply a very minimal load to a PaymentServer via the redemption endpoint.
#
# This requires a PaymentServer run something like:
#
# $ ./result/bin/PaymentServer-exe --issuer Trivial --http-port 8080 --stripe-key-path ../stripe.secret --database SQLite3 --database-path ./vouchers.db
#
# It also requires some vouchers to be marked as paid somehow. The vouchers
# are aaa0 through aaaN where N is the PARALLELISM you select. You can
# accomplish this by:
#
# $ for n in $(seq 0 30); do sqlite3 vouchers.db "insert into vouchers (name) values ('aaa$n')"; done
#
# Then the test can be run as many times as necessary. Repeated redemptions
# are allowed since the same tokens are used on every run.
#
# Originally written for https://github.com/PrivateStorageio/PaymentServer/issues/60
from
__future__
import
division
from
time
import
(
time
,
)
from
json
import
(
dumps
,
)
from
treq.client
import
(
HTTPClient
,
)
from
twisted.web.client
import
(
Agent
,
readBody
,
)
from
twisted.internet.task
import
(
react
,
)
from
twisted.internet.defer
import
(
inlineCallbacks
,
gatherResults
,
returnValue
,
)
PARALLELISM
=
30
@inlineCallbacks
def
redeem
(
client
,
index
):
times
=
[]
for
i
in
range
(
16
):
before
=
time
()
response
=
yield
client
.
post
(
url
=
"
http://127.0.0.1:8080/v1/redeem
"
,
data
=
dumps
({
"
redeemVoucher
"
:
"
aaa{}
"
.
format
(
index
),
"
redeemTokens
"
:
[
"
foo-{}-{}
"
.
format
(
index
,
i
)],
"
redeemCounter
"
:
i
,
}),
headers
=
{
"
content-type
"
:
"
application/json
"
},
)
after
=
time
()
duration
=
int
((
after
-
before
)
*
1000
)
print
(
"
Request complete in {}ms
"
.
format
(
duration
))
body
=
yield
readBody
(
response
)
assert
response
.
code
==
200
,
(
response
.
code
,
body
)
times
.
append
(
duration
)
returnValue
(
times
)
def
mean
(
xs
):
return
sum
(
xs
)
/
len
(
xs
)
def
percentile
(
n
,
xs
):
return
sorted
(
xs
)[
int
(
len
(
xs
)
/
100
*
95
)]
def
median
(
xs
):
return
percentile
(
50
,
xs
)
@react
@inlineCallbacks
def
main
(
reactor
):
client
=
HTTPClient
(
Agent
(
reactor
))
ds
=
list
(
redeem
(
client
,
i
)
for
i
in
range
(
PARALLELISM
)
)
times
=
[]
for
result
in
(
yield
gatherResults
(
ds
)):
times
.
extend
(
result
)
print
(
"
min: {}
"
.
format
(
min
(
times
)))
print
(
"
max: {}
"
.
format
(
max
(
times
)))
print
(
"
mean: {}
"
.
format
(
mean
(
times
)))
print
(
"
median: {}
"
.
format
(
median
(
times
)))
print
(
"
95th: {}
"
.
format
(
percentile
(
95
,
times
)))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment