[英]New to Connection Pooling
So I am new to connection pooling.所以我是连接池的新手。 I am trying to determine how to use a pool in order to speed up my query.
我正在尝试确定如何使用池来加快查询速度。 I have a query that works, but I dont think I am using the pool correct.
我有一个有效的查询,但我认为我没有正确使用池。 Here is the syntax, if you see anywhere I could be more efficient please let me know.
这是语法,如果您看到任何我可以提高效率的地方,请告诉我。
try:
db=mysql.connector.connect(poolname="mypool", pool_size=10, **config)
cursor.execute(query1)
df1=create_df(cursor)
cursor.execute(query2)
df2=create_df(cursor)
cursor.execute(query3)
df3=create_df(cursor)
Your question didn't make it clear how cursor
comes from db
.您的问题没有说明
cursor
如何来自db
。
Consider using sqlalchemy .考虑使用sqlalchemy 。 Then you get automatic pooling for free.
然后你就可以免费获得自动池化。
import pandas as pd
import sqlalchemy as sa
engine = sa.create_engine(your_local_mysql_url_with_credentials)
with engine.connect() as con:
df1 = pd.read_sql(query1, con)
df2 = pd.read_sql(query2, con)
df3 = pd.read_sql(query3, con)
The pool winds up being an attribute of engine
.池最终成为
engine
的一个属性。 In practice you'll seldom care about inspecting it, since it Just Works, hanging onto a server TCP connection across queries.在实践中,您很少关心检查它,因为它只是工作,跨查询挂在服务器 TCP 连接上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.