are you on 0.5.6 ?  major speed issues related to flush() were repaired
around 0.5.4 or so.


Yannick Gingras wrote:
>
> Greetings Alchemists,
>   maybe I'm doing something wrong but it seems to me that commiting a
> session, especially one with many objects (say, 150k), requires a lot
> of processing power.
>
> In the following script, commiting the session takes roughly three
> times longer then generating the objects, no matter what the database
> is: I get roughly the same ration with Postgres, MySQL, and SQLite.
> That's to be expected since it's at commit time that we actually send
> the objects to the database.  What puzzles me though is that `top`
> suggests that the process is CPU bound on the Python side, not
> io-bound on the database side.
>
> Am I doing something wrong?  Beside the obvious raw SQL statements, is
> there a way to speed things up?
>
> Here is my example script:
> ------------------------------
> from timeit import timeit
>
> from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import sessionmaker
> from sqlalchemy.orm import relation
>
> engine = create_engine('sqlite:////tmp/foo.db', echo=False)
> Base = declarative_base()
>
> class Department(Base):
>     __tablename__ = 'department'
>     id = Column(Integer, primary_key=True)
>
> class Employee(Base):
>     __tablename__ = 'employee'
>
>     id = Column(String, primary_key=True)
>     dept_id = Column(Integer, ForeignKey("department.id"))
>     dept = relation(Department, backref="employees")
>
> Base.metadata.create_all(engine)
>
> session = sessionmaker(bind=engine)()
>
> def insert():
>     for i in range(50000):
>         dept = Department(id=i)
>         session.add(dept)
>         for j in range(3):
>             emp = Employee(id="%d-%d" % (i, j))
>             session.add(emp)
>             dept.employees.append(emp)
>
> print timeit(insert, number=1)
> print timeit(session.commit, number=1)
> ------------------------------
>
> --
> Yannick Gingras
> http://ygingras.net
> http://confoo.ca -- track coordinator
> http://montrealpython.org -- lead organizer
>

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to