2013-05-11 50 views
1

我有使用SQLAlchemy的访问运行远程server.The远程服务器具有的MySQL-server5.5上的后援相关部分运行DATABSE python程序测量的MySQL的服务器上的插入时间和查询时间代码如下。使用SQLAlchemy的

log = core.getLogger() 

engine = create_engine('mysql://[email protected]/nwtopology', echo=False) 

Base = declarative_base() 
Session = sessionmaker(bind=engine) 
session = Session() 

class SourcetoPort(Base): 
    """""" 
    __tablename__ = 'source_to_port' 
    id = Column(Integer, primary_key=True) 
    port_no  = Column(Integer) 
    src_address = Column(String(32),index=True) 

    #----------------------------------------- 
    def __init__(self, src_address,port_no): 
     """""" 
     self.src_address = src_address  
    self.port_no  = port_no 


#create tables 
Base.metadata.create_all(engine) 

#query code 
r_res = session.query(SourcetoPort).filter_by(src_address=str(packet.src)).first() 

#insert code 
entry = SourcetoPort(src_address=str(packet.src) , port_no=packet_in.in_port) 
#add the record to the session object 
session.add(entry) 
#add the record to the session object 
session.commit() 
end = time.time() 
elapsed = end - start 

我已经计算出平均查询并将超过64个条目的时间插入数据库。

平均查询时间被发现是0.001424秒

平均插入时间被发现是0.03144秒

这意味着你可以做一个第二OR 702最多32个插入查询一个第二。

这些数字看起来是否合理。我对数据库和sqlalchemy非常陌生。我的程序需要更多数量的insert和quries.Also每个表的数量和表本身的数量本身会显着增加。This是裸minumum原型的条目的最小数目和一个表。

我的问题,这是怎样的表现,一旦能够从database.?If期望不是有什么预期的性能?是否有任何已知的机制,以加快这一进程?任何帮助,高度赞赏。

回答