PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Long running SQL query via ActiveRecord blocking the entire Ruby process?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Long running SQL query via ActiveRecord blocking the entire Ruby process?

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 20h26   #1
estebanjang@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Long running SQL query via ActiveRecord blocking the entire Ruby process?


To my surprise, a long running SQL query via ActiveRecord blocks an
entire Ruby process (all the other threads are blocked while the
thread that runs the SQL query is waiting for the result set)

Has anyone else found this to be the case? (am I mistaken?)
Is there any way to avoid this other than spawning a separate process?

[Ruby version 1.8.4, ActiveRecord version 1.14.4 on Linux]

-Steve

  Réponse avec citation
Vieux 06/11/2007, 20h47   #2
Szymon Rozga
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Long running SQL query via ActiveRecord blocking the entire Ruby process?

It is my understanding that Ruby threads are green threads.

see: http://en.wikipedia.org/wiki/Green_threads
"Also a green thread may block all other threads if performing a
blocking I/O operation. In order to avoid these problems, green
threads must use asynchronous I/O operations, but the added complexity
increases latency."

I seem to remember reading about Ruby threads and IO blocking, but
cannot find it.

Hope the above answers some questions.

Does anyone know of a solution?

-Szymon

On Nov 6, 3:26 pm, estebanj...@gmail.com wrote:
> To my surprise, a long running SQL query via ActiveRecord blocks an
> entire Ruby process (all the other threads are blocked while the
> thread that runs the SQL query is waiting for the result set)
>
> Has anyone else found this to be the case? (am I mistaken?)
> Is there any way to avoid this other than spawning a separate process?
>
> [Ruby version 1.8.4, ActiveRecord version 1.14.4 on Linux]
>
> -Steve



  Réponse avec citation
Vieux 06/11/2007, 21h07   #3
Jones, Brian - McClatchy Interactive
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Long running SQL query via ActiveRecord blocking the entire Ruby process?

> To my surprise, a long running SQL query via ActiveRecord=20
> blocks an entire Ruby process (all the other threads are=20
> blocked while the thread that runs the SQL query is waiting=20
> for the result set)
>=20
> Has anyone else found this to be the case? (am I mistaken?)=20
> Is there any way to avoid this other than spawning a separate process?
>=20
> [Ruby version 1.8.4, ActiveRecord version 1.14.4 on Linux]


As far as I know, things like Mongrel obtain a global lock -> run the
request through rails -> and release the lock. Rails isn't thread safe,
and a great deal of hackery depends upon this non-threaded mode of
operation. To handle multiple requests, you'll need multiple processes.


I'm curious, do you have something attempting to run the same rails in
multiple ruby threads at the same time?

Brian

  Réponse avec citation
Vieux 06/11/2007, 21h47   #4
Jeremy Kemper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Long running SQL query via ActiveRecord blocking the entire Rubyprocess?

On 11/6/07, estebanjang@gmail.com <estebanjang@gmail.com> wrote:
> To my surprise, a long running SQL query via ActiveRecord blocks an
> entire Ruby process (all the other threads are blocked while the
> thread that runs the SQL query is waiting for the result set)
>
> Has anyone else found this to be the case? (am I mistaken?)
> Is there any way to avoid this other than spawning a separate process?


The postgres and oracle adapters support async queries which won't
block Ruby threads, or you can use any of the pure-Ruby database
drivers.

Forking processes is probably better though.

jeremy

  Réponse avec citation
Vieux 06/11/2007, 23h01   #5
snacktime
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Long running SQL query via ActiveRecord blocking the entire Rubyprocess?

On Nov 6, 2007 12:30 PM, <estebanjang@gmail.com> wrote:
>
> To my surprise, a long running SQL query via ActiveRecord blocks an
> entire Ruby process (all the other threads are blocked while the
> thread that runs the SQL query is waiting for the result set)
>
> Has anyone else found this to be the case? (am I mistaken?)
> Is there any way to avoid this other than spawning a separate process?
>


C extensions that block will block the whole process, as they
basically interrupt ruby's thread schedular while they are running.
Unless the extension is written with this in mind, which most are not.

Chris

  Réponse avec citation
Vieux 06/11/2007, 23h28   #6
ara.t.howard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Long running SQL query via ActiveRecord blocking the entire Rubyprocess?


On Nov 6, 2007, at 2:47 PM, Jeremy Kemper wrote:

> The postgres and oracle adapters support async queries which won't
> block Ruby threads, or you can use any of the pure-Ruby database
> drivers.
>
> Forking processes is probably better though.
>


i'll be releasing a background job manager for rails in a few
days... fyi.

a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h43.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11793 seconds with 14 queries