@@ -28,6 +28,11 @@ create or replace function get(uri character varying) returns text as $$
28
28
return data.read()
29
29
$$
30
30
language plpython2u volatile;
31
+ create or replace function get_requests(uri character varying) returns text as $$
32
+ import requests
33
+ r = requests.get(uri)
34
+ return r.text
35
+ $$ language plpython2u volatile;
31
36
32
37
-- plpython3u
33
38
create extension plpython3u; -- do beforehand: sudo apt-get install postgresql-plpython3-9.6
@@ -52,6 +57,7 @@ postgres@dev:~$ #### http, localhost
52
57
postgres@dev:~ $ echo " select left(http_get.content, 50) from http_get('http://localhost/robots.txt');" > ~ /local_http_c.sql
53
58
postgres@dev:~ $ echo " select left(_get, 50) from http_client._get('http://localhost/robots.txt', 2);" > ~ /local_http_plsh.sql
54
59
postgres@dev:~ $ echo " select left(get, 50) from get('http://localhost/robots.txt');" > ~ /local_http_python.sql
60
+ postgres@dev:~ $ echo " select left(get_requests, 50) from get_requests('http://localhost/robots.txt');" > ~ /local_http_python_requests.sql
55
61
postgres@dev:~ $ echo " select left(get_python3, 50) from get_python3('http://localhost/robots.txt');" > ~ /local_http_python3.sql
56
62
postgres@dev:~ $ pgbench -f ~ /local_http_c.sql -c 10 -t 100 test
57
63
starting vacuum...end.
@@ -89,6 +95,18 @@ number of transactions actually processed: 1000/1000
89
95
latency average = 2.203 ms
90
96
tps = 4539.882871 (including connections establishing)
91
97
tps = 4602.161543 (excluding connections establishing)
98
+ postgres@dev:~ $ pgbench -f ~ /local_http_python_requests.sql -c 10 -t 100 test
99
+ starting vacuum...end.
100
+ transaction type: /var/lib/postgresql/local_http_python_requests.sql
101
+ scaling factor: 1
102
+ query mode: simple
103
+ number of clients: 10
104
+ number of threads: 1
105
+ number of transactions per client: 100
106
+ number of transactions actually processed: 1000/1000
107
+ latency average = 16.941 ms
108
+ tps = 590.275913 (including connections establishing)
109
+ tps = 591.321016 (excluding connections establishing)
92
110
postgres@dev:~ $ pgbench -f ~ /local_http_python3.sql -c 10 -t 100 test
93
111
starting vacuum...end.
94
112
transaction type: /var/lib/postgresql/local_http_python3.sql
@@ -292,6 +310,7 @@ Method | Latency, ms | TPS
292
310
pgsql-http (C) | 5.01 | 2007
293
311
plsh (curl) | 19.20 | 521.6
294
312
plpython2u | 2.20 | 4602
313
+ plpython2u-requests | 16.94 | 591.3
295
314
plpython3u | 3.18 | 3175
296
315
297
316
### Results for HTTP, ya.ru:
0 commit comments