Skip to content

Commit a5a8342

Browse files
committed
Tuning: Seem to have a good config
1 parent ad31921 commit a5a8342

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed
Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,58 @@
1-
from locust import HttpLocust, TaskSet, task
1+
from locust import HttpUser, TaskSet, task, Locust
22
import bs4
33
import random
44
import sys, os
55

66

7-
class WebsiteTasks(TaskSet):
7+
class WebsiteTasks(HttpUser):
88
def on_start(self):
99
res = self.client.get("/runestone/default/user/login")
10-
pq = bs4.BeautifulSoup(res.content, features="lxml")
10+
pq = bs4.BeautifulSoup(res.content)
1111
# Get the csrf key for successful submission
1212
i = pq.select('input[name="_formkey"]')
1313
token = i[0]["value"]
1414
# login a user
1515
try:
16-
user = os.environ["RUNESTONE_TESTUSER"]
17-
pw = os.environ["RUNESTONE_TESTPW"]
16+
user = "testuser1"
17+
pw = "xxx"
1818
except:
1919
print("ERROR please set RUNESTONE_TESTUSER and RUNESTONE_TESTPW ")
2020
sys.exit(-1)
2121
res = self.client.post(
2222
"/runestone/default/user/login",
2323
{"username": user, "password": pw, "_formkey": token, "_formname": "login"},
2424
)
25+
# Switch to fopp
26+
res = self.client.post("/runestone/default/coursechooser/fopp",
27+
data={"course": "fopp"})
28+
2529
# Get the index and make a list of all chapters/subchapters
26-
res = self.client.get("/runestone/books/published/fopp/index.html")
27-
pq = bs4.BeautifulSoup(res.content, features="lxml")
30+
res = self.client.get("/ns/books/published/fopp/index.html")
31+
pq = bs4.BeautifulSoup(res.content, features="html.parser")
2832
pages = pq.select(".toctree-l2 a")
33+
print(f"Found {len(pages)} pages in the book")
2934
self.bookpages = [p["href"] for p in pages]
35+
print(f"Found {len(self.bookpages)} pages in the book")
3036

3137
@task(5)
3238
def index(self):
3339
self.client.get("/runestone")
3440

41+
@task(5)
42+
def course(self):
43+
self.client.get("/ns/course/index")
44+
45+
@task(5)
46+
def doassign(self):
47+
self.client.get("/assignment/student/doAssignment?assignment_id=90")
48+
3549
@task(20)
3650
def boookpage(self):
3751
# pick a page at random
3852
url = random.choice(self.bookpages)
39-
base = "/runestone/books/published/fopp/"
53+
base = "/ns/books/published/fopp/"
4054
res = self.client.get(base + url)
41-
pq = bs4.BeautifulSoup(res.content, features="lxml")
55+
pq = bs4.BeautifulSoup(res.content)
4256
# client.get ONLY gets the html, so we need to simulate getting all
4357
# of the static assets ourselves.
4458
for s in pq.select("script"):
@@ -53,10 +67,14 @@ def boookpage(self):
5367
css = self.client.get(
5468
base + s["href"].replace("../", ""), name="css"
5569
)
56-
57-
58-
class WebsiteUser(HttpLocust):
59-
host = "http://localhost"
60-
task_set = WebsiteTasks
61-
min_wait = 1000
62-
max_wait = 15000
70+
data = {
71+
"lastPageUrl": base + url,
72+
"lastPageScrollLocation": 0,
73+
"completionFlag": 0,
74+
"pageLoad": True,
75+
"markingComplete": False,
76+
"markingIncomplete": False,
77+
"course": "fopp",
78+
"isPtxBook": False,
79+
}
80+
self.client.post("/ns/logger/updatelastpage", json=data)

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ services:
2121
- POSTGRESQL_USERNAME=${POSTGRESQL_USERNAME}
2222
- POSTGRESQL_PASSWORD=${POSTGRESQL_PASSWORD}
2323
- PGBOUNCER_AUTH_TYPE=trust #md5 or scram-sha-256
24-
- PGBOUNCER_DEFAULT_POOL_SIZE=30
24+
- PGBOUNCER_DEFAULT_POOL_SIZE=25
2525
- PGBOUNCER_POOL_MODE=transaction
2626
- PGBOUNCER_MAX_PREPARED_STATEMENTS=100
27+
- PGBOUNCER_MAX_CLIENT_CONN=250
2728
- PGBOUNCER_STATS_USERS=runestone
2829

2930

0 commit comments

Comments
 (0)