It is not efficient at all to individually flush each of 20,000 new
rows to the database (the flush() happens implicitly via autoflush
when you query for the row) and read them back one by one. I would
change the primary key fields to auto increment in mysql so you don't
have to set them yourself and replace create() with something like
(untested):
user_num=0
for p in xrange(1000):
project = Project(name='project'+str(p))
session.add(project)
for _ in xrange(20):
user_num+=1
user = User(login='login'+str(user_num), projects =
[project])
session.add(user)
session.flush()
On Thu, Feb 19, 2009 at 11:07 AM, Spes <[email protected]> wrote:
>
> Hi guys,
>
> I'm working on some project which fetches data across the network and
> stores tham on single place into database. I want to easily work with
> data so I'm looking on different Python ORMs. I tried SQLAlchemy,
> Elixir, SQLObject, ZODB, ORM in Django. For each I wrote simple
> example which looks like this:
>
> Have:
> - project class
> - user class
> and binding table between projects and users.
>
> Repeat this 1000 and measure time of whole task:
> 1. create project
> 2. repeat 20 times:
> 2.1 create new user
> 2.2 get this user (to see slow down of additional SELECT)
> 2.3 assign user to project
>
> On Core2 Duo 2.40GHz, 3MB L2 cache, 2GB memory, Fedora x86-64, MySQL
> MYISAM backend and SQLAlchemy version in 0.4.8 I get these times:
> - SQLAlchemy: 164 s
> - SQLObject: 26.59s
> (there is not big difference between versions 0.4.8 and 0.5.2)
>
> You can find source codes here:
> http://www.fi.muni.cz/~xholer/tmp/orm_sqlobject.py
> http://www.fi.muni.cz/~xholer/tmp/orm_alchemy.py
>
> Can anybody show me what's wrong with my examples and why is the
> performance of SQLAlchemy (and subsequently of the Elixir) so
> terrible?
>
> Many thanks, have a nice day!
> Vlastimil Holer
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---