Created
March 2, 2012 14:23
-
-
Save ipconfiger/1958660 to your computer and use it in GitHub Desktop.
测试mysql长连接和短连接直接在tornado下的性能问题
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import MySQLdb | |
def get_conn(): | |
db = MySQLdb.connect("localhost","alex","1qasw2","test") | |
#db.autocommit(False) | |
return db | |
def query(db): | |
cursor=db.cursor() | |
cursor.execute("select * from test_user where id = 1") | |
result=cursor.fetchall() | |
cursor.close() | |
if result: | |
return result | |
db=get_conn() | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
query(db) | |
self.write("Hello, world") | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(6666) | |
tornado.ioloop.IOLoop.instance().start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import MySQLdb | |
def get_conn(): | |
db = MySQLdb.connect("localhost","alex","1qasw2","test") | |
#db.autocommit(False) | |
return db | |
def query(db): | |
cursor=db.cursor() | |
cursor.execute("select * from test_user where id = 1") | |
result=cursor.fetchall() | |
cursor.close() | |
if result: | |
return result | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
db=get_conn() | |
query(db) | |
db.close() | |
self.write("Hello, world") | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(6666) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment