File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments