[storm] Storm thread-safe question

R Pish rpishcr at gmail.com
Tue Aug 5 04:43:36 UTC 2014


So, we started using storm recently and we are still in a development
process, but before going any further, we want to know if we are making
things right.

The application being built is a REST API developed using Falcon Framework.

When the application starts, we import a file (models.meta) which has the
following code

...
database_dsn = "%s://%s:%s@%s:%s/%s" % (db_driver, db_user, db_pwd,
db_host, db_port, db_name)
from zope.component import provideUtility, getUtility
from storm.zope.interfaces import IZStorm
from storm.zope.zstorm import global_zstorm
provideUtility(global_zstorm, IZStorm)
zstorm = getUtility(IZStorm)
zstorm.set_default_uri("store_provider", database_dsn)

And, in the file that contains the class that handles the calls to a
particular entity in the REST API has the following (abbreviated):

from models.meta import zstorm
class LoginResource:
    # POST /login
    def on_post(self, req, resp):
        store = zstorm.get("store_provider")
        user = store.find...
...

So, the code above is the basic idea we are currently starting to use.
I wanted to know if just by doing: store = zstorm.get("store_provider") in
each function that handles a particular request, is enough to guarantee
that the app will be thread-safe and, for example, that 2 concurrent
requests will get their non-blocking stores and use the database without
blocking each other? (storm does this internally and transparently for the
developer?)

I read the following in Storm-Manual:
"Therefore, the best policy is usually to create a Store object for each
thread which needs one. One convenient way to manage this is to implement a
"threadsafe" Store manager, which creates a Store for each thread when that
thread first requests one, and then keeps the Store cached in a
thread-local dictionary. This approach is taken by ZStorm to provide Store
objects to each thread."

If our idea above is wrong, what would we could do to make our app
thread-safe?

Thanks a lot in advance for any help
Regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/storm/attachments/20140804/a79a6d03/attachment.html>


More information about the storm mailing list