@@ -28,6 +28,11 @@ create or replace function get(uri character varying) returns text as $$
2828 return data.read()
2929$$
3030language 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;
3136
3237-- plpython3u
3338create extension plpython3u; -- do beforehand: sudo apt-get install postgresql-plpython3-9.6
@@ -52,6 +57,7 @@ postgres@dev:~$ #### http, localhost
5257postgres@dev:~ $ echo " select left(http_get.content, 50) from http_get('http://localhost/robots.txt');" > ~ /local_http_c.sql
5358postgres@dev:~ $ echo " select left(_get, 50) from http_client._get('http://localhost/robots.txt', 2);" > ~ /local_http_plsh.sql
5459postgres@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
5561postgres@dev:~ $ echo " select left(get_python3, 50) from get_python3('http://localhost/robots.txt');" > ~ /local_http_python3.sql
5662postgres@dev:~ $ pgbench -f ~ /local_http_c.sql -c 10 -t 100 test
5763starting vacuum...end.
@@ -89,6 +95,18 @@ number of transactions actually processed: 1000/1000
8995latency average = 2.203 ms
9096tps = 4539.882871 (including connections establishing)
9197tps = 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)
92110postgres@dev:~ $ pgbench -f ~ /local_http_python3.sql -c 10 -t 100 test
93111starting vacuum...end.
94112transaction type: /var/lib/postgresql/local_http_python3.sql
@@ -292,6 +310,7 @@ Method | Latency, ms | TPS
292310pgsql-http (C) | 5.01 | 2007
293311plsh (curl) | 19.20 | 521.6
294312plpython2u | 2.20 | 4602
313+ plpython2u-requests | 16.94 | 591.3
295314plpython3u | 3.18 | 3175
296315
297316### Results for HTTP, ya.ru:
0 commit comments