Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / apps / rest-test / restful_demo_session_expense.html @ master

History | View | Annotate | Download (1.47 KB)

1 6c82c4a7 Rick Pratt
<html>
2 4315b76b Rick Pratt
<head><title>RESTful Demo - HTTPS/TCP Session Setup and Teardown Expense</title></head>
3 6c82c4a7 Rick Pratt
<body>
4
<pre>
5
#!/usr/bin/env python
6
7
# The RESTful GDP Gateway's HTTPS/TCP Session Setup and Teardown is expensive.
8
#
9
# A single read or append per session (as shown in this script) has relatively
10
# low performance and high latency.
11
#
12
# Where multiple reads or appends are needed, performance and latency are
13
# significantly improved by amortizing a single HTTPS/TCP session over
14
# multiple actions (see restful_demo_session_amortized.html).
15
16
import json
17
import requests
18
import time
19
import random
20
import sys
21
22
test_auth = ("PLEASE_EDIT_username", "PLEASE_EDIT_password")
23
json_header = { 'Content-type': 'application/json' }
24
25
def GDPwrite(data, gcl_name):
26
    
27
    start_time = time.time()
28
    wrec = requests.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v1/gcl/" +
29
                         gcl_name,
30
                         auth = test_auth,
31
                         timeout = 60,
32
                         headers = json_header,
33
                         data = data) # serialize json_body
34
35
    success =  wrec.status_code == 200
36
    end_time = time.time()
37
    return (end_time - start_time, success)
38
39
if __name__=="__main__":
40
41
    if len(sys.argv)<2:
42
        sys.stderr.write("Usage: %s <logname>\n" % sys.argv[0])
43
        sys.exit(-1)
44
45
    logname = sys.argv[1]
46
    for i in xrange(10):
47
        random_data = str(random.randint(0, 2**32))
48
        print GDPwrite(random_data, logname)
49
50
</pre>
51
</body>
52
</html>