Initial commit

This commit is contained in:
Ian Gulliver
2019-01-29 00:34:24 +00:00
parent e99a035e88
commit dac364befe
8 changed files with 309 additions and 0 deletions

53
mysql-insert.py Executable file
View File

@@ -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))

View File

@@ -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))

24
mysql-network-latency-public.py Executable file
View File

@@ -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))

50
mysql-single-row-select.py Executable file
View File

@@ -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))

56
postgres-insert.py Executable file
View File

@@ -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))

View File

@@ -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))

View File

@@ -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))

54
postgres-single-row-select.py Executable file
View File

@@ -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))