Skip to content

Commit 249ce23

Browse files
use own SCW instance to speed things up
1 parent 6705008 commit 249ce23

10 files changed

+225
-88
lines changed

.terraform.lock.hcl

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export SCW_SECRET_KEY="xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1111
### Launch
1212

1313
```bash
14-
terraform apply -var="tasks_url=https://gist.githubusercontent.com/guillaumepotier/1cde30986851e7a915e0ddce57c997f5/raw/4fda21ad5d4d7b1d054b58bd8f7900d3de71d0ed/tasks.py" -var="locust_username=guillaume" -var="locust_password=wisembly" -var="workers_nb=3"
14+
terraform apply -var="tasks_url=https://gist.githubusercontent.com/guillaumepotier/fee14623614f64035cd53da92298e10d/raw/b49c688a13879a57535b6bfaebf5461eb7999f0e/loading_quotes_moods.py" -var="locust_username=guillaume" -var="locust_password=wisembly" -var="workers_nb=9"
1515
```
1616

1717

locustfile.py

+20-73
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,40 @@
11
import time
22
import json
3+
import uuid
34
import hashlib
45

5-
from locust import HttpUser, task, between
6+
import random
7+
import string
68

7-
# FastHttpUser is 5-6X faster than HttpUser but does not support headers persist in on_start
8-
# https://github.com/locustio/locust/issues/2035
9-
# from locust.contrib.fasthttp import FastHttpUser
9+
from locust import HttpUser, task, constant
10+
from locust.contrib.fasthttp import FastHttpUser
1011

1112
KEYWORD = "tmc"
13+
SURVEY_HASH = "2d2e36786c5f1dee206620413313dd8031d0ef8f"
14+
SURVEY_ITEM_HASH = "5f3e2a52627e5902ed5987177ff546d47e645066"
15+
TOKEN="660383a9cd886a70c0bed7a37cc1e4a66cd8a48a"
1216

13-
class QuickstartUser(HttpUser):
14-
wait_time = between(1, 5)
17+
class QuickstartUser(FastHttpUser):
18+
wait_time = constant(10000)
1519

1620
def shaHash(self, string):
1721
m = hashlib.sha1()
1822
m.update(string.encode('utf-8'))
1923
return str(m.hexdigest())
2024

21-
@task
2225
def on_start(self):
23-
token = ""
24-
payload = {"data":{"type":"apiSession","attributes":{"app_id":"wisembly_app","hash":"67608b0127f18b15cc8bee4c4f9caeb9cbde5b0c"},"relationships":{}}}
25-
headers = {'content-type': 'application/vnd.api+json'}
26-
27-
clientParams = {
28-
"catch_response": True,
29-
"verify": False,
30-
"data": json.dumps(payload),
31-
"headers": headers
32-
}
33-
34-
with self.client.post("/api/6/authentication", **clientParams) as response:
35-
if response.status_code == 200:
36-
json_response = json.loads(response.text)
37-
token = response.json()['data']['attributes']['token']
3826

39-
self.client.headers = {
40-
'content-type': 'application/vnd.api+json',
41-
'Wisembly-Token': token
42-
}
43-
44-
response.success()
45-
else:
46-
response.failure("Could not get credentials")
47-
48-
@task(100)
49-
def get_event(self):
50-
self.client.get("/api/6/event/%s" % KEYWORD)
51-
self.client.post("/api/6/event/%s/watchers" % KEYWORD)
52-
53-
clientParams = {
54-
"data": json.dumps({"event": {"keyword": KEYWORD}}),
55-
"headers": {'content-type': 'application/json'}
56-
}
57-
58-
self.client.post("/api/4/users/node/credentials", **clientParams)
59-
60-
self.client.get("/api/6/event/%s/medias?limit=25&offset=0&active=true" % KEYWORD)
61-
self.client.get("/api/6/event/%s/surveys?limit=50" % KEYWORD)
62-
self.client.get("/api/6/event/%s/quotes?sort=recent&limit=10&unmoderated=false" % KEYWORD)
63-
64-
@task(5)
65-
def post_quote(self):
66-
hash = self.shaHash(str(time.time()))
67-
payload = {"data":{"id": hash,"type":"quote","attributes":{"quote":"Hello %s" % hash,"username":"Guillaume Potier","via":"tablet"},"relationships":{}}}
68-
clientParams = {
69-
"catch_response": True,
70-
"verify": False,
71-
"data": json.dumps(payload),
72-
}
73-
74-
with self.client.post("/api/6/event/%s/quotes" % KEYWORD, **clientParams) as response:
75-
if response.status_code == 201:
76-
response.success()
77-
else:
78-
response.failure("Could not post quote")
27+
message = ''.join(random.choices(string.ascii_lowercase, k=10))
28+
payload = {"data":{"type":"surveyAnswer","attributes":{"username":"foo","via":"web","items":[{"hash":SURVEY_ITEM_HASH,"value":message}]},"relationships":{"survey":{"data":{"id":SURVEY_HASH,"type":"survey"}}}}}
29+
headers = {'content-type': 'application/vnd.api+json'}
7930

80-
@task(20)
81-
def post_mood(self):
82-
clientParams = {
83-
"catch_response": True,
84-
"verify": False,
31+
newHeaders = {
32+
'content-type': 'application/vnd.api+json',
33+
'Wisembly-Token': TOKEN
8534
}
8635

87-
with self.client.get("/api/4/event/%s/mood?mood=tada" % KEYWORD, **clientParams) as response:
88-
if response.status_code == 201:
89-
response.success()
90-
else:
91-
response.failure("Could not post quote")
92-
36+
self.client.post(f'/api/6/event/{KEYWORD}/surveys/{SURVEY_HASH}/answers', data=json.dumps(payload), headers=newHeaders)
9337

38+
@task
39+
def do_nothing(self):
40+
pass

main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ provider "scaleway" {
1414
}
1515

1616
data "scaleway_instance_image" "locust" {
17-
image_id = "ff48b73a-097d-4685-b996-d3ebe50636ea"
17+
image_id = "eb32085c-a9fa-4477-b717-11553fc79e99"
1818
}
1919

2020
module "master" {

scripts/answer_tagcloud.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import time
2+
import json
3+
import uuid
4+
import hashlib
5+
6+
import random
7+
import string
8+
9+
from locust import HttpUser, task, constant
10+
from locust.contrib.fasthttp import FastHttpUser
11+
12+
KEYWORD = "tmc"
13+
SURVEY_HASH = "2d2e36786c5f1dee206620413313dd8031d0ef8f"
14+
SURVEY_ITEM_HASH = "5f3e2a52627e5902ed5987177ff546d47e645066"
15+
16+
class QuickstartUser(FastHttpUser):
17+
wait_time = constant(10000)
18+
19+
def shaHash(self, string):
20+
m = hashlib.sha1()
21+
m.update(string.encode('utf-8'))
22+
return str(m.hexdigest())
23+
24+
def on_start(self):
25+
26+
token = ''
27+
payload = {"data":{"type": "apiSession", "attributes": {"app_id":"wisembly_app","hash":"67608b0127f18b15cc8bee4c4f9caeb9cbde5b0c"}, "relationships":{}}}
28+
headers = {'content-type': 'application/vnd.api+json'}
29+
30+
clientParams = {
31+
"catch_response": True,
32+
"verify": False,
33+
"data": json.dumps(payload),
34+
"headers": headers
35+
}
36+
37+
with self.client.post("/api/6/authentication", **clientParams) as response:
38+
if response.status_code == 200:
39+
token = response.json()['data']['attributes']['token'];
40+
response.success()
41+
else:
42+
response.failure("Could not get credentials")
43+
44+
message = ''.join(random.choices(string.ascii_lowercase, k=10))
45+
payload = {"data":{"type":"surveyAnswer","attributes":{"username":"foo","via":"web","items":[{"hash":SURVEY_ITEM_HASH,"value":message}]},"relationships":{"survey":{"data":{"id":SURVEY_HASH,"type":"survey"}}}}}
46+
headers = {'content-type': 'application/vnd.api+json'}
47+
48+
newHeaders = {
49+
'content-type': 'application/vnd.api+json',
50+
'Wisembly-Token': token
51+
}
52+
53+
self.client.post(f'/api/6/event/{KEYWORD}/surveys/{SURVEY_HASH}/answers', data=json.dumps(payload), headers=newHeaders)
54+
55+
@task
56+
def do_nothing(self):
57+
pass
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import time
2+
import json
3+
import uuid
4+
import hashlib
5+
6+
import random
7+
import string
8+
9+
from locust import HttpUser, task, constant
10+
from locust.contrib.fasthttp import FastHttpUser
11+
12+
KEYWORD = "tmc"
13+
SURVEY_HASH = "2d2e36786c5f1dee206620413313dd8031d0ef8f"
14+
SURVEY_ITEM_HASH = "5f3e2a52627e5902ed5987177ff546d47e645066"
15+
TOKEN="d416ef2d47c98b6804b5637ce3f386837196f3e5"
16+
17+
class QuickstartUser(FastHttpUser):
18+
wait_time = constant(10000)
19+
20+
def shaHash(self, string):
21+
m = hashlib.sha1()
22+
m.update(string.encode('utf-8'))
23+
return str(m.hexdigest())
24+
25+
def on_start(self):
26+
27+
message = ''.join(random.choices(string.ascii_lowercase, k=10))
28+
payload = {"data":{"type":"surveyAnswer","attributes":{"username":"foo","via":"web","items":[{"hash":SURVEY_ITEM_HASH,"value":message}]},"relationships":{"survey":{"data":{"id":SURVEY_HASH,"type":"survey"}}}}}
29+
headers = {'content-type': 'application/vnd.api+json'}
30+
31+
newHeaders = {
32+
'content-type': 'application/vnd.api+json',
33+
'Wisembly-Token': TOKEN
34+
}
35+
36+
self.client.post(f'/api/6/event/{KEYWORD}/surveys/{SURVEY_HASH}/answers', data=json.dumps(payload), headers=newHeaders)
37+
38+
@task
39+
def do_nothing(self):
40+
pass

scripts/arriving_on_a_wiz.py

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
class QuickstartUser(HttpUser):
1313
wait_time = between(0.1, 1.1)
1414

15-
@task
1615
def on_start(self):
1716
token = ""
1817
payload = {"data":{"type":"apiSession","attributes":{"app_id":"wisembly_app","hash":"67608b0127f18b15cc8bee4c4f9caeb9cbde5b0c"},"relationships":{}}}

scripts/loading_quotes_moods.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import time
2+
import json
3+
import hashlib
4+
5+
from locust import HttpUser, task, between
6+
7+
# FastHttpUser is 5-6X faster than HttpUser but does not support headers persist in on_start
8+
# https://github.com/locustio/locust/issues/2035
9+
# from locust.contrib.fasthttp import FastHttpUser
10+
11+
KEYWORD = "tmc"
12+
13+
class QuickstartUser(HttpUser):
14+
wait_time = between(20, 45)
15+
16+
def shaHash(self, string):
17+
m = hashlib.sha1()
18+
m.update(string.encode('utf-8'))
19+
return str(m.hexdigest())
20+
21+
def on_start(self):
22+
token = ""
23+
payload = {"data":{"type":"apiSession","attributes":{"app_id":"wisembly_app","hash":"67608b0127f18b15cc8bee4c4f9caeb9cbde5b0c"},"relationships":{}}}
24+
headers = {'content-type': 'application/vnd.api+json'}
25+
26+
clientParams = {
27+
"catch_response": True,
28+
"verify": False,
29+
"data": json.dumps(payload),
30+
"headers": headers
31+
}
32+
33+
with self.client.post("/api/6/authentication", **clientParams) as response:
34+
if response.status_code == 200:
35+
json_response = json.loads(response.text)
36+
token = response.json()['data']['attributes']['token']
37+
38+
self.client.headers = {
39+
'content-type': 'application/vnd.api+json',
40+
'Wisembly-Token': token
41+
}
42+
43+
response.success()
44+
else:
45+
response.failure("Could not get credentials")
46+
47+
self.client.get("/api/6/event/%s" % KEYWORD)
48+
self.client.post("/api/6/event/%s/watchers" % KEYWORD)
49+
50+
clientParams = {
51+
"data": json.dumps({"event": {"keyword": KEYWORD}}),
52+
"headers": {'content-type': 'application/json'}
53+
}
54+
55+
self.client.post("/api/4/users/node/credentials", **clientParams)
56+
57+
self.client.get("/api/6/event/%s/medias?limit=25&offset=0&active=true" % KEYWORD)
58+
self.client.get("/api/6/event/%s/surveys?limit=50" % KEYWORD)
59+
self.client.get("/api/6/event/%s/quotes?sort=recent&limit=10&unmoderated=false" % KEYWORD)
60+
61+
@task(10)
62+
def post_quote(self):
63+
hash = self.shaHash(str(time.time()))
64+
payload = {"data":{"id": hash,"type":"quote","attributes":{"quote":"Hello %s" % hash,"username":"Guillaume Potier","via":"tablet"},"relationships":{}}}
65+
clientParams = {
66+
"catch_response": True,
67+
"verify": False,
68+
"data": json.dumps(payload),
69+
}
70+
71+
with self.client.post("/api/6/event/%s/quotes" % KEYWORD, **clientParams) as response:
72+
if response.status_code == 201:
73+
response.success()
74+
else:
75+
response.failure("Could not post quote")
76+
77+
@task(30)
78+
def post_mood(self):
79+
clientParams = {
80+
"catch_response": True,
81+
"verify": False,
82+
}
83+
84+
with self.client.get("/api/4/event/%s/mood?mood=tada" % KEYWORD, **clientParams) as response:
85+
if response.status_code == 201:
86+
response.success()
87+
else:
88+
response.failure("Could not post quote")
89+
90+
@task(70)
91+
def do_nothing(self):
92+
pass
93+

startup-master.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
22
set -x
3-
apt update
4-
apt upgrade -y
5-
groupadd -f locust
6-
useradd -m locust -g locust || echo "user already exists"
7-
apt install -y htop emacs-nox wget iftop iotop python3-pip
8-
pip install locust
3+
# apt update
4+
# apt upgrade -y
5+
# groupadd -f locust
6+
# useradd -m locust -g locust || echo "user already exists"
7+
# apt install -y htop emacs-nox wget iftop iotop python3-pip
8+
# pip install locust
99
echo '* - nofile 1000000' >> /etc/security/limits.conf
1010
echo '* - nproc 1000000' >> /etc/security/limits.conf
1111

startup-worker.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
22
set -x
3-
apt update
4-
apt upgrade -y
5-
groupadd -f locust
6-
useradd -m locust -g locust || echo "user already exists"
7-
apt install -y htop emacs-nox wget iftop iotop python3-pip
8-
pip install locust
3+
# apt update
4+
# apt upgrade -y
5+
# groupadd -f locust
6+
# useradd -m locust -g locust || echo "user already exists"
7+
# apt install -y htop emacs-nox wget iftop iotop python3-pip
8+
# pip install locust
99
echo '* - nofile 1000000' >> /etc/security/limits.conf
1010
echo '* - nproc 1000000' >> /etc/security/limits.conf
1111

0 commit comments

Comments
 (0)