Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
07efe8c7
Commit
07efe8c7
authored
5 years ago
by
Seva
Browse files
Options
Downloads
Patches
Plain Diff
tools: add locust proxy_benchmark.py
parent
5c78bf38
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/proxy_benchmark.py
+65
-0
65 additions, 0 deletions
tools/proxy_benchmark.py
with
65 additions
and
0 deletions
tools/proxy_benchmark.py
0 → 100644
+
65
−
0
View file @
07efe8c7
# Copyright (C) 2017-2019 Savoir-faire Linux Inc.
# Author: Vsevolod Ivanov <vsevolod.ivanov@savoirfairelinux.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Run with: locust -f proxy_benchmark.py --host http://127.0.0.1:8080
from
locust
import
HttpLocust
,
TaskSet
from
random
import
randint
import
urllib.request
import
base64
import
json
words_url
=
"
http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain
"
words_resp
=
urllib
.
request
.
urlopen
(
words_url
)
words
=
words_resp
.
read
().
decode
().
splitlines
()
headers
=
{
'
content-type
'
:
'
application/json
'
}
def
rand_list_value
(
mylist
):
return
mylist
[
randint
(
0
,
len
(
mylist
)
-
1
)]
def
put_key
(
l
):
key
=
rand_list_value
(
words
)
val
=
rand_list_value
(
words
)
print
(
"
Put/get: key={} value={}
"
.
format
(
key
,
val
))
data
=
base64
.
b64encode
(
val
.
encode
()).
decode
()
print
(
"
Base64 encoding: value={} encoded={}
"
.
format
(
val
,
data
))
l
.
client
.
post
(
"
/
"
+
key
,
data
=
json
.
dumps
({
"
data
"
:
data
}),
headers
=
headers
,
catch_response
=
True
)
def
get_key
(
l
):
key
=
rand_list_value
(
words
)
print
(
"
Get: key={}
"
.
format
(
key
))
l
.
client
.
get
(
"
/
"
+
key
)
def
get_stats
(
l
):
l
.
client
.
get
(
"
/stats
"
)
class
UserBehavior
(
TaskSet
):
tasks
=
{
get_key
:
1
,
put_key
:
1
}
def
on_start
(
self
):
put_key
(
self
)
get_key
(
self
)
def
on_stop
(
self
):
get_stats
()
class
WebsiteUser
(
HttpLocust
):
task_set
=
UserBehavior
min_wait
=
5000
max_wait
=
9000
print
(
"
Initiate the benchmark at http://127.0.0.1:8089/
"
)
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