Message from discussion
How to handle lock on database row when using tornado?
Received: by 10.180.73.242 with SMTP id o18mr2608540wiv.0.1349965738811;
Thu, 11 Oct 2012 07:28:58 -0700 (PDT)
X-BeenThere: python-tornado@googlegroups.com
Received: by 10.180.73.226 with SMTP id o2ls4182754wiv.0.gmail; Thu, 11 Oct
2012 07:28:52 -0700 (PDT)
Received: by 10.180.101.9 with SMTP id fc9mr379864wib.3.1349965732080;
Thu, 11 Oct 2012 07:28:52 -0700 (PDT)
Received: by 10.180.101.9 with SMTP id fc9mr379863wib.3.1349965732063;
Thu, 11 Oct 2012 07:28:52 -0700 (PDT)
Return-Path: <serge.ko...@gmail.com>
Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45])
by gmr-mx.google.com with ESMTPS id ci6si871096wib.3.2012.10.11.07.28.52
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 11 Oct 2012 07:28:52 -0700 (PDT)
Received-SPF: pass (google.com: domain of serge.ko...@gmail.com designates 74.125.82.45 as permitted sender) client-ip=74.125.82.45;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of serge.ko...@gmail.com designates 74.125.82.45 as permitted sender) smtp.mail=serge.ko...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-wg0-f45.google.com with SMTP id dq12so1275336wgb.26
for <python-tornado@googlegroups.com>; Thu, 11 Oct 2012 07:28:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type;
bh=Yc399c+x8B9z1HYiT7riz6Zj0R1w8V29a+cH456Bb5g=;
b=miFRxDvL4+EWH76JLrZFrVTKHdufQlB2ndzrUcZNqqY9E43h9YwbXr2z6+/JfxPqaB
pKSqJfWBkmliCd0wWp0Jcdc2e+ma2z4KIRqtw3v2qbeS+wQp9tb3qmyv3lKF0seSkUVn
5nsaGXCYjitjlvSILzRsZi+Lv5KQBCVZYCIXQIUUXVq1fE/IYObhUll6ykgAi5Vxs/oE
E4T3hBc2J4ITQcVWmwEqxuTsfVjKmE6WS0kKt94YXmrzfQSHm3PybDhwfdHNLtGgn2QZ
5PtcXIwm9bNF9jDFad3nNtbsaizNjarAi+TbQRAUXFUscU0Euf0IZpeqbNRp1ltxJaL6
YHgw==
MIME-Version: 1.0
Received: by 10.180.87.74 with SMTP id v10mr2667295wiz.21.1349965731932; Thu,
11 Oct 2012 07:28:51 -0700 (PDT)
Received: by 10.216.14.145 with HTTP; Thu, 11 Oct 2012 07:28:51 -0700 (PDT)
In-Reply-To: <d399a6d8-5acc-44bb-9b06-2e76aa543dee@googlegroups.com>
References: <d399a6d8-5acc-44bb-9b06-2e76aa543dee@googlegroups.com>
Date: Thu, 11 Oct 2012 17:28:51 +0300
Message-ID: <CAJZrG8hegi0-A2XTGxrq=d2iVofk_ohKOc3eMFWfRDJ_vwT...@mail.gmail.com>
Subject: Re: [tornado] How to handle lock on database row when using tornado?
From: "Serge S. Koval" <serge.ko...@gmail.com>
To: python-tornado@googlegroups.com
Content-Type: multipart/alternative; boundary=f46d0444032ee928f504cbc963a2
--f46d0444032ee928f504cbc963a2
Content-Type: text/plain; charset=ISO-8859-1
Hi,
Did you try https://github.com/FSX/momoko? Or you want to use ORM?
As far as I know, there are no asynchronous ORMs with Tornado support. So,
it is either background thread with a queue, which can use blocking ORM or
raw SQL through asynchronous driver.
Serge.
On Thu, Oct 11, 2012 at 4:36 PM, Jimmy <li.jiam...@gmail.com> wrote:
> My application has a need to lock a row in database for update. But when
> another request comes to hit the same row, the query will be pending until
> the previous lock is release. But this will hold all requests in the same
> thread.
>
> I have searched for several ways of get around of this issue. Not sure
> which is the best way to handle it. I would like to hear your experience
> about this issue. My potential solutions:
> 1. move the locked query to backend job. and return the response when the
> job finished.
> pro: clean and follow async manner of tornado
> con: it may keep the connect open for longer time
> 2. Use async db library to load.
> pro: fast and follow async manner
> con: few async db library supports sqlalchemy for orm, which is
> important to us. I have tried twisted adbapi, and adb with MySQL. but the
> experience is not good (Maybe because I'm new to twisted). gevent with
> psycopg2 works with sqlalchemy, but I can't enjoy the async support from
> tornado (I can only use gevent.spawn and join for async, and tornado is
> only for wsgi application).
> 3. Set short timeout to each query. (This is the last thing I want to do)
> pro: easy and simple
> con: Bad user experience bcz of timeout.
>
> I would like to know if there is a general solution for issue like this.
>
> Thank you.
>
--f46d0444032ee928f504cbc963a2
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi,<div><br></div><div>=A0Did you try=A0<a href=3D"https://github.com/FSX/m=
omoko">https://github.com/FSX/momoko</a>? Or you want to use ORM?</div><div=
><br></div><div>=A0As far as I know, there are no asynchronous ORMs with To=
rnado support. So, it is either background thread with a queue, which can u=
se blocking ORM or raw SQL through asynchronous driver.</div>
<div><br></div><div>Serge.<br><br><div class=3D"gmail_quote">On Thu, Oct 11=
, 2012 at 4:36 PM, Jimmy <span dir=3D"ltr"><<a href=3D"mailto:li.jiaming=
@gmail.com" target=3D"_blank">li.jiam...@gmail.com</a>></span> wrote:<br=
><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1=
px #ccc solid;padding-left:1ex">
My application has a need to lock a row in database for update. But when an=
other request comes to hit the same row, the query will be pending until th=
e previous lock is release. But this will hold all requests in the same thr=
ead.=A0<div>
<br></div><div>I have searched for several ways of get around of this issue=
. Not sure which is the best way to handle it. I would like to hear your ex=
perience about this issue. My potential solutions:</div><div>1. move the lo=
cked query to backend job. and return the response when the job finished.=
=A0</div>
<div>=A0 =A0 pro: clean and follow async manner of tornado</div><div>=A0 =
=A0 con: it may keep the connect open for longer time</div><div>2. Use asyn=
c db library to load.=A0</div><div>=A0 =A0 pro: fast and follow async manne=
r</div><div>
=A0 =A0 con: few async db library supports sqlalchemy for orm, which is imp=
ortant to us. I have tried twisted adbapi, and adb with MySQL. but the expe=
rience is not good (Maybe because I'm new to twisted). gevent with psyc=
opg2 works with sqlalchemy, but I can't enjoy the async support from to=
rnado (I can only use gevent.spawn and join for async, and tornado is only =
for wsgi application).</div>
<div>3. Set short timeout to each query. (This is the last thing I want to =
do)</div><div>=A0 =A0 pro: easy and simple</div><div>=A0 =A0 con: Bad user =
experience bcz of timeout.=A0</div><div><br></div><div>I would like to know=
if there is a general solution for issue like this.=A0</div>
<div><br></div><div>Thank you.</div></blockquote></div><br></div>
--f46d0444032ee928f504cbc963a2--