Hi All,
I need an advice, take a look at this code sample:

engine = create_engine(url,encoding = 'utf-8',echo = False,pool_size =
100)

metadata = MetaData()

object_table = Table('_object', metadata,
                   Column('id', Integer, primary_key=True),
                   Column('_owner_id', Integer),
                   Column('_created', DateTime),
                   Column('_creator_id', Integer),
                   Column('_modified', DateTime),
                   Column('_modifier_id', Integer),
                   Column('class_id', Unicode(60)),
                   Column('type', Integer),
                   Column('singular_label', Unicode(200)),
                   Column('plural_label', Unicode(200))
                   )
class Object(object):
    pass

mapper(Object,object_table)


def application(environ, start_response):
    Session = sessionmaker(bind=engine)
    session = Session()
    status = '200 OK'

    """
    #1. use session
    output = '\n,'.join(['%s: %s %s %s %s %s %s %s %s'%(o.id,
 
o._owner_id,o._created,o._created,o._creator_id,
 
o.class_id,o.type,o.singular_label,o.plural_label)
                       for o in session.query(Object)])
    """


    #2. use raw sql
    s = text('''
               SELECT _object.id AS _object_id,
                      _object._owner_id AS _object__owner_id,
                      _object._created AS _object__created,
                      _object._creator_id AS _object__creator_id,
                      _object._modified AS _object__modified,
                      _object._modifier_id AS _object__modifier_id,
                      _object.class_id AS _object_class_id,
                      _object.type AS _object_type,
                      _object.singular_label AS
_object_singular_label,
                      _object.plural_label AS _object_plural_label
                      FROM _object
    ''')
    output = '\n,'.join([str(p) for p in session.connection().execute
(s).fetchall()])

    session.close()
    with open('/home/alex/integrity/data/a1/xdoc/schema.xml','r') as
f:
        output = '%s %s'%(f.read(),output.encode('utf-8'))

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

As you see there are 2 options for query - raw mysql query and ORM
based one.
I've performed some tests on my PC

ab -n 1000 -c 100 http://localhost/l

ORM: (option 1 turned on)

Document Path:          /l
Document Length:        87305 bytes

Concurrency Level:      100
Time taken for tests:   17.352274 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      88662825 bytes
HTML transferred:       88439965 bytes
Requests per second:    57.63 [#/sec] (mean)
Time per request:       1735.227 [ms] (mean)
Time per request:       17.352 [ms] (mean, across all concurrent
requests)
Transfer rate:          4989.78 [Kbytes/sec] received

RAW: (option 2)

Document Path:          /l
Document Length:        89533 bytes

Concurrency Level:      100
Time taken for tests:   8.951501 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      89753000 bytes
HTML transferred:       89533000 bytes
Requests per second:    111.71 [#/sec] (mean)
Time per request:       895.150 [ms] (mean)
Time per request:       8.952 [ms] (mean, across all concurrent
requests)
Transfer rate:          9791.54 [Kbytes/sec] received

Pentium 4 2.4/1.5GB mem/apache2(mpm-worker)/mod_wsgi

I've done lot's of attempts to avoid occasions and formula is the
same: performance drops almost 2 times.  And this distance grows when
increasing number of iteration.

My "big" app issues about 5 queries using ORM, so in the end I get
10-13  requests/second (ORM) vs 35-40 requests/second using raw.
What can be done to increase the performance of my server in ORM based
case?

Any advice would be appreciated.

Regards, Alex

P.S.

this part:

with open('/home/alex/integrity/data/a1/xdoc/schema.xml','r') as f:
        output = '%s %s'%(f.read(),output.encode('utf-8'))

is here just to add some traffic to response (file size is 7kb )

There are ~20 records in the _object table

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to