Comment 3 for bug 322887

Revision history for this message
Marc Tardif (cr3) wrote :

In an attempt to potentially isolate the problem further, the following multi-threaded application was written which strictly makes Storm calls. The database queries are those which were observed in the PostgreSQL log when running the above request to reproduce the problem. Unfortunately, this doesn't seem to reproduce the blocking problem which seems to indicate that the problem might be in the Zope3 threading pool.

import sys, os
import transaction
from threading import Thread
from zope.component import getUtility
from canonical.certify.application import load_config
from canonical.certify.interfaces import IStoreSelector, MAIN_STORE

THREAD_COUNT = 40
ITERATION_COUNT = 40

def do_function(thread_num):
    main_store = getUtility(IStoreSelector).get(MAIN_STORE)
    for i in range(ITERATION_COUNT):
        try:
            transaction.begin()
            result = main_store.execute("""SELECT hardware.access_context_id, hardware.account_id, hardware.aliases, hardware.canonical_id, hardware.category, hardware.c
            result = main_store.execute("""UPDATE hardware SET foo_time='2009-01-29 12:30:42.443242' WHERE hardware.id = 123""")
            result = main_store.execute("""SELECT certificate.completed, certificate.hardware_id, certificate.id, certificate.name, certificate.release, certificate.secu
            result = main_store.execute("""SELECT account.access_context_id, account.billing_city, account.billing_country, account.billing_postal_code, account.billing_
            result = main_store.execute("""SELECT COUNT(*) FROM certificate WHERE certificate.hardware_id = 123""")
            result = main_store.execute("""UPDATE hardware SET foo_time='2009-01-29 12:30:42.747807' WHERE hardware.id = 123""")
            result = main_store.execute("""SELECT DISTINCT hardware.access_context_id, hardware.account_id, hardware.aliases, hardware.canonical_id, hardware.category, h
            result = main_store.execute("""SELECT DISTINCT hardware.access_context_id, hardware.account_id, hardware.aliases, hardware.canonical_id, hardware.category, h
            result = main_store.execute("""SELECT DISTINCT hardware.access_context_id, hardware.account_id, hardware.aliases, hardware.canonical_id, hardware.category, h
            transaction.commit()
        except Exception, e:
            print e

def main(argv):
    load_config(os.path.abspath("."), "application.conf")

    threads = []
    for i in range(THREAD_COUNT):
        thread = Thread(target=do_function, args=[i])
        threads.append(thread)
        thread.start()

    while True:
        alives = [t for t in threads if t.isAlive()]
        for alive in alives:
            try:
                alive.join(1)
            except KeyboardInterrupt:
                sys.exit(1)
        else:
            break

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))