I know many process not use same connect, Because this will be a problem .
BUT, run the under code , mysql request is block , then many process start to query sql at the same time , the sql is "select sleep(10)" , They are one by one.
I not found code abort lock/mutux in MySQLdb/mysql.c , Why there is no problem ? I think there will be problems with same connection fd in general . But pass my test, only block io, problems not arise . Where is the lock ?
import time
import multiprocessing
import MySQLdb
db = MySQLdb.connect("127.0.0.1","xiaorui.cc","xiaorui.cc","rui" )
def func(*args):
while 1:
cursor = db.cursor()
cursor.execute("select sleep(10)")
data = cursor.fetchall()
print len(data)
cursor.close()
print time.time()
time.sleep(0.1)
if __name__ == "__main__":
task = []
for i in range(20):
p = multiprocessing.Process(target = func, args = (i,))
p.start()
task.append(p)
for i in task:
i.join()
result log, we found each request interval is ten seconds.
I know many process not use same connect, Because this will be a problem .
BUT, run the under code , mysql request is block , then many process start to query sql at the same time , the sql is "select sleep(10)" , They are one by one.
I not found code abort lock/mutux in MySQLdb/mysql.c , Why there is no problem ? I think there will be problems with same connection fd in general . But pass my test, only block io, problems not arise . Where is the lock ?
result log, we found each request interval is ten seconds.
tcpdump log:
we found each request interval is ten seconds two.
Thanks You .