Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 151f9b6

Browse files
committedSep 25, 2014
Benchmark event handling
1 parent d1df5f1 commit 151f9b6

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
 

‎pymysqlreplication/tests/benchmark.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# This is a sample script in order to make benchmark
4+
# on library speed.
5+
#
6+
#
7+
8+
import pymysql
9+
import time
10+
import random
11+
import os
12+
from pymysqlreplication import BinLogStreamReader
13+
from pymysqlreplication.row_event import *
14+
15+
16+
def execute(con, query):
17+
c = con.cursor()
18+
c.execute(query)
19+
return c
20+
21+
database = {
22+
"host": "localhost",
23+
"user": "root",
24+
"passwd": "",
25+
"use_unicode": True,
26+
"charset": "utf8",
27+
"db": "pymysqlreplication_test"
28+
}
29+
30+
conn = pymysql.connect(**database)
31+
32+
execute(conn, "DROP DATABASE IF EXISTS pymysqlreplication_test")
33+
execute(conn, "CREATE DATABASE pymysqlreplication_test")
34+
conn = pymysql.connect(**database)
35+
execute(conn, "CREATE TABLE test (i INT) ENGINE = MEMORY")
36+
execute(conn, "INSERT INTO test VALUES(1)")
37+
execute(conn, "RESET MASTER")
38+
39+
if os.fork() != 0:
40+
print("Start insert data")
41+
while True:
42+
execute(conn, "UPDATE test SET i = i + 1;")
43+
else:
44+
stream = BinLogStreamReader(connection_settings=database,
45+
server_id=3,
46+
resume_stream=False,
47+
blocking=True,
48+
only_events = [UpdateRowsEvent])
49+
start = time.clock()
50+
i = 0.0
51+
for binlogevent in stream:
52+
i += 1.0
53+
if i % 1000 == 0:
54+
print("%d event by seconds (%d total)" % (i / (time.clock() - start), i))
55+
stream.close()
56+
57+

0 commit comments

Comments
 (0)
Please sign in to comment.