From dac364befe9d126a945e883b562ac123ebc386b6 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 29 Jan 2019 00:34:24 +0000 Subject: [PATCH] Initial commit --- mysql-insert.py | 53 +++++++++++++++++++++++++++ mysql-network-latency-private.py | 24 +++++++++++++ mysql-network-latency-public.py | 24 +++++++++++++ mysql-single-row-select.py | 50 ++++++++++++++++++++++++++ postgres-insert.py | 56 +++++++++++++++++++++++++++++ postgres-network-latency-private.py | 24 +++++++++++++ postgres-network-latency-public.py | 24 +++++++++++++ postgres-single-row-select.py | 54 ++++++++++++++++++++++++++++ 8 files changed, 309 insertions(+) create mode 100755 mysql-insert.py create mode 100755 mysql-network-latency-private.py create mode 100755 mysql-network-latency-public.py create mode 100755 mysql-single-row-select.py create mode 100755 postgres-insert.py create mode 100755 postgres-network-latency-private.py create mode 100755 postgres-network-latency-public.py create mode 100755 postgres-single-row-select.py diff --git a/mysql-insert.py b/mysql-insert.py new file mode 100755 index 0000000..1853b28 --- /dev/null +++ b/mysql-insert.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 + +import time +import MySQLdb + +############ +LOW_ROWS = 500 +HIGH_ROWS = 1000 +SAMPLES = 100 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = MySQLdb.connect(host='35.235.123.231', user='root', password='foobar', db='benchmark') +c = db.cursor() + +c.execute('DROP TABLE IF EXISTS pushrows') +c.execute(''' +CREATE TABLE pushrows ( + id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY +) ENGINE=InnoDB +''') + +c.execute('DROP PROCEDURE IF EXISTS pushrows') +c.execute(''' +CREATE PROCEDURE pushrows (IN num INT) +BEGIN + DECLARE x INT; + SET x = 0; + WHILE x < num DO + INSERT INTO pushrows VALUES (); + SET X = x + 1; + END WHILE; +END +''') + +def MeanExecutionTime(rows, samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('CALL pushrows(%d)' % rows) + end = time.perf_counter() + + return (end - start) / samples + +low = MeanExecutionTime(LOW_ROWS, SAMPLES) +high = MeanExecutionTime(HIGH_ROWS, SAMPLES) + +per_row = (high - low) / (HIGH_ROWS - LOW_ROWS) +base = high - (HIGH_ROWS * per_row) + +print('%dus/row' % (per_row * MICROSECONDS_PER_SECOND)) +print('%dus commit' % (base * MICROSECONDS_PER_SECOND)) diff --git a/mysql-network-latency-private.py b/mysql-network-latency-private.py new file mode 100755 index 0000000..bf22ea2 --- /dev/null +++ b/mysql-network-latency-private.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import time +import MySQLdb + +############ +SAMPLES = 10000 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = MySQLdb.connect(host='10.108.0.4', user='root', password='foobar') +c = db.cursor() + +def MeanExecutionTime(samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('SELECT 1') + end = time.perf_counter() + + return (end - start) / samples + +print('%dus' % (MeanExecutionTime(SAMPLES) * MICROSECONDS_PER_SECOND)) diff --git a/mysql-network-latency-public.py b/mysql-network-latency-public.py new file mode 100755 index 0000000..093ff39 --- /dev/null +++ b/mysql-network-latency-public.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import time +import MySQLdb + +############ +SAMPLES = 10000 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = MySQLdb.connect(host='35.235.123.231', user='root', password='foobar', db='benchmark') +c = db.cursor() + +def MeanExecutionTime(samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('SELECT 1') + end = time.perf_counter() + + return (end - start) / samples + +print('%dus' % (MeanExecutionTime(SAMPLES) * MICROSECONDS_PER_SECOND)) diff --git a/mysql-single-row-select.py b/mysql-single-row-select.py new file mode 100755 index 0000000..39bed5e --- /dev/null +++ b/mysql-single-row-select.py @@ -0,0 +1,50 @@ +#!/usr/bin/python3 + +import time +import MySQLdb + +############ +LOW_ROWS = 500 +HIGH_ROWS = 1000 +SAMPLES = 100 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = MySQLdb.connect(host='35.235.123.231', user='root', password='foobar', db='benchmark') +c = db.cursor() + +c.execute('DROP TABLE IF EXISTS pullrows') +c.execute(''' +CREATE TABLE pullrows ( + id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY +) ENGINE=InnoDB +''') +c.execute('INSERT INTO pullrows VALUES (1)') + +c.execute('DROP PROCEDURE IF EXISTS pullrows') +c.execute(''' +CREATE PROCEDURE pullrows (IN num INT) +BEGIN + DECLARE x INT; + SET x = 0; + WHILE x < num DO + SELECT * FROM pullrows WHERE id=1; + SET X = x + 1; + END WHILE; +END +''') + +def MeanExecutionTime(rows, samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('CALL pullrows(%d)' % rows) + end = time.perf_counter() + + return (end - start) / samples + +diff = MeanExecutionTime(HIGH_ROWS, SAMPLES) - MeanExecutionTime(LOW_ROWS, SAMPLES) +per_row = diff / (HIGH_ROWS - LOW_ROWS) + +print('%dus/row' % (per_row * MICROSECONDS_PER_SECOND)) diff --git a/postgres-insert.py b/postgres-insert.py new file mode 100755 index 0000000..545e6ff --- /dev/null +++ b/postgres-insert.py @@ -0,0 +1,56 @@ +#!/usr/bin/python3 + +import time +import psycopg2 + +############ +LOW_ROWS = 500 +HIGH_ROWS = 1000 +SAMPLES = 100 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = psycopg2.connect('host=35.235.77.254 user=postgres password=foobar dbname=benchmark') +c = db.cursor() + +c.execute('DROP TABLE IF EXISTS pushrows') +c.execute(''' +CREATE TABLE pushrows ( + id BIGSERIAL PRIMARY KEY +) +''') + +c.execute('DROP FUNCTION IF EXISTS pushrows (numrows INTEGER)') +c.execute(''' +CREATE FUNCTION pushrows (numrows INTEGER) RETURNS void AS $$ +DECLARE + rec RECORD; + x INTEGER := 0; +BEGIN + LOOP + EXIT WHEN x = numrows; + x := x + 1; + INSERT INTO pushrows VALUES (DEFAULT); + END LOOP; +END +$$ language plpgsql +''') + +def MeanExecutionTime(rows, samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('SELECT pushrows(%d)' % rows) + end = time.perf_counter() + + return (end - start) / samples + +low = MeanExecutionTime(LOW_ROWS, SAMPLES) +high = MeanExecutionTime(HIGH_ROWS, SAMPLES) + +per_row = (high - low) / (HIGH_ROWS - LOW_ROWS) +base = high - (HIGH_ROWS * per_row) + +print('%dus/row' % (per_row * MICROSECONDS_PER_SECOND)) +print('%dus commit' % (base * MICROSECONDS_PER_SECOND)) diff --git a/postgres-network-latency-private.py b/postgres-network-latency-private.py new file mode 100755 index 0000000..37468f3 --- /dev/null +++ b/postgres-network-latency-private.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import time +import psycopg2 + +############ +SAMPLES = 10000 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = psycopg2.connect('host=10.108.1.3 user=postgres password=foobar') +c = db.cursor() + +def MeanExecutionTime(samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('SELECT 1') + end = time.perf_counter() + + return (end - start) / samples + +print('%dus' % (MeanExecutionTime(SAMPLES) * MICROSECONDS_PER_SECOND)) diff --git a/postgres-network-latency-public.py b/postgres-network-latency-public.py new file mode 100755 index 0000000..89fc611 --- /dev/null +++ b/postgres-network-latency-public.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import time +import psycopg2 + +############ +SAMPLES = 10000 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = psycopg2.connect('host=35.235.77.254 user=postgres password=foobar dbname=benchmark') +c = db.cursor() + +def MeanExecutionTime(samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('SELECT 1') + end = time.perf_counter() + + return (end - start) / samples + +print('%dus' % (MeanExecutionTime(SAMPLES) * MICROSECONDS_PER_SECOND)) diff --git a/postgres-single-row-select.py b/postgres-single-row-select.py new file mode 100755 index 0000000..91d7f08 --- /dev/null +++ b/postgres-single-row-select.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 + +import time +import psycopg2 + +############ +LOW_ROWS = 500 +HIGH_ROWS = 1000 +SAMPLES = 100 +############ + + +MICROSECONDS_PER_SECOND = 1000000 + +db = psycopg2.connect('host=35.235.77.254 user=postgres password=foobar dbname=benchmark') +c = db.cursor() + +c.execute('DROP TABLE IF EXISTS pullrows') +c.execute(''' +CREATE TABLE pullrows ( + id BIGSERIAL PRIMARY KEY +) +''') +c.execute('INSERT INTO pullrows VALUES (1)') + +c.execute('DROP FUNCTION IF EXISTS pullrows (numrows INTEGER)') +c.execute(''' +CREATE FUNCTION pullrows (numrows INTEGER) RETURNS SETOF RECORD AS $$ +DECLARE + rec RECORD; + x INTEGER := 0; +BEGIN + LOOP + EXIT WHEN x = numrows; + x := x + 1; + SELECT * FROM pullrows WHERE id=1 INTO rec; + RETURN NEXT rec; + END LOOP; +END +$$ language plpgsql +''') + +def MeanExecutionTime(rows, samples): + start = time.perf_counter() + for _ in range(samples): + c.execute('SELECT * FROM pullrows(%d) AS (id BIGINT)' % rows) + end = time.perf_counter() + + return (end - start) / samples + +diff = MeanExecutionTime(HIGH_ROWS, SAMPLES) - MeanExecutionTime(LOW_ROWS, SAMPLES) +per_row = diff / (HIGH_ROWS - LOW_ROWS) + +print('%dus/row' % (per_row * MICROSECONDS_PER_SECOND))