-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadTestHttp.py
More file actions
36 lines (34 loc) · 1.2 KB
/
Copy pathLoadTestHttp.py
File metadata and controls
36 lines (34 loc) · 1.2 KB
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
from multiprocessing import Pool
import random
"""
The function makes a call to random end point
"""
def f( x):
import pycurl, json
items = [
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php',
'http://localhost/test.php'
]
rand = random.randint(0,9)
url = 'http://localhost/test.php'
data = json.dumps({"From": "user@example.com", "To": "receiver@example.com", "Subject": "Pycurl", "TextBody": "Some text"})
c = pycurl.Curl()
c.setopt(pycurl.URL, items[rand])
c.setopt(pycurl.HTTPHEADER, ['X-Postmark-Server-Token: API_TOKEN_HERE','Accept: application/json'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data)
c.perform()
return x
if __name__ == '__main__':
pool = Pool(processes=100) # start 4 worker processes
result = pool.apply_async(f, [500]) # evaluate "f(10)" asynchronously
print result.get(timeout=1) # prints "100" unless your computer is *very* slow
pool.map(f, range(1000)) # prints "[0, 1, 4,..., 81]"