-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocustfile.py
64 lines (51 loc) · 1.82 KB
/
locustfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from locust import HttpUser, TaskSet, task, between
import random, uuid, time, io, requests, urllib, os, base64, json
IMAGES = [
'https://raw.githubusercontent.com/Wook-2/ImageReader/locust/static/menu.jpg',
'https://raw.githubusercontent.com/Wook-2/ImageReader/locust/static/roadSign.jpeg',
'https://raw.githubusercontent.com/Wook-2/ImageReader/locust/static/roadsign2.jpeg',
'https://raw.githubusercontent.com/Wook-2/ImageReader/locust/static/signboard.jpg',
'https://raw.githubusercontent.com/Wook-2/ImageReader/locust/static/signboard2.jpg'
]
responsetime = 0
response200 = 0
def getFilenameFromURL(url):
parsedUrl = urllib.parse.urlparse(url)
return os.path.basename(parsedUrl.path)
def fileopen(image):
fetched = requests.get(image)
f_image = (
getFilenameFromURL(image),
io.BytesIO(fetched.content),
)
return f_image
class UserBehavior(TaskSet):
@task
def ITS(self):
global responsetime, response200
response_aver = 0
req_id = str(uuid.uuid4())
image = random.choice(IMAGES)
index = IMAGES.index(image)
image_bytes = fileopen(image)
start = time.time()
response = self.client.post(
"/upload",
files={
'file': image_bytes,
}
)
duration = time.time() - start
if response.status_code == 200:
response200 += 1
responsetime += duration
if response200 > 0:
response_aver = responsetime/response200
print(('out', req_id, duration, index, response.status_code, response_aver))
TARGET_RPS = 1
class WebsiteUser(HttpUser):
tasks = [UserBehavior]
def wait_time(self):
target_wait = between(0, 2 / TARGET_RPS)(self)
print(("wait", target_wait))
return target_wait