# ActiveRecord, blocking or async, logging, syslog/udp

**URL:** <https://www.ruby-forum.com/t/activerecord-blocking-or-async-logging-syslog-udp/114356>\
**Category:** Rails\
**Created:** [September 11, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/activerecord-blocking-or-async-logging-syslog-udp/114356 "2007-09-11T19:21:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [September 11, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/activerecord-blocking-or-async-logging-syslog-udp/114356/1 "2007-09-11T19:21:21Z")

</div>

Here’s a gedanken experiment for those w/ far more knowledge than I  
about  
ActiveRecord, etc.:

Let’s say my database is very remote and on a very slow machine. Let’s  
further say that my app has an action that leads to a very simple insert  
into the “impressions” table of the db, a la “INSERT INTO  
impressions(docid)  
VALUES($docid);” - and let’s say the db automatically adds created\_at as  
now() and autoincrements primary key.

Will RoR/AR block on this insert? If so is there a way to make it  
non-blocking (asynchronous)?

Alternatively, let’s say I wanted to log such impressions on a remote  
log  
server using UDP and syslog - any guidance on doing that? (Not all  
logging  
mind you, but just this specific case).

Thanks,

Marc

---

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [September 11, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/activerecord-blocking-or-async-logging-syslog-udp/114356/2 "2007-09-11T20:36:25Z")

</div>

In general ActiveRecord will block on this kind of request.

There’s a product called BackgroundDB that was built for offloading slow  
pages.  
I’m not sure what the status is on that product, or if there’s anything  
newer.

This tends to be problematic but you can also do this.

If you want to return the page quickly without waiting for the outcome,  
you can fork a thread to handle the mysql insert, and return a page that  
doesn’t contain the results of that insert.

From past experience the mysql driver doesn’t deal well with threads.  
(One of the reasons why Rails is single threaded), so YMMV.

Marc B. wrote:

> Here’s a gedanken experiment for those w/ far more knowledge than I  
> about  
> ActiveRecord, etc.:
> 
> Let’s say my database is very remote and on a very slow machine. Let’s  
> further say that my app has an action that leads to a very simple insert  
> into the “impressions” table of the db, a la “INSERT INTO  
> impressions(docid)  
> VALUES($docid);” - and let’s say the db automatically adds created\_at as  
> now() and autoincrements primary key.
> 
> Will RoR/AR block on this insert? If so is there a way to make it  
> non-blocking (asynchronous)?
> 
> Alternatively, let’s say I wanted to log such impressions on a remote  
> log  
> server using UDP and syslog - any guidance on doing that? (Not all  
> logging  
> mind you, but just this specific case).
> 
> Thanks,
> 
> Marc

---

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/activerecord-blocking-or-async-logging-syslog-udp/114356/3 "2007-09-17T13:23:59Z")

</div>

What about mysql’s “INSERT DELAYED” - that would allow the server to  
take  
over, let the client proceed (non-blocking, asynchronous) - and/or  
perhaps  
INSERT IGNORE ?

m

---

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/activerecord-blocking-or-async-logging-syslog-udp/114356/4 "2007-09-17T13:25:12Z")

</div>

insert delayed only work with myisam talbes, and you are surely using  
innodb table.

a cool work around can came form mysql-proxy, wich can hold the loging,  
and return imediatly.  
[http://forge.mysql.com/wiki/MySQL\_Proxy](http://forge.mysql.com/wiki/MySQL_Proxy)

mysql-proxy can be used to scale your database with master slave, using  
slave to do the read, and master for the write.  
far more better than balance and other tcp load balancer.

Marc B. a Ã©crit :

> ```
> This tends to be problematic but you can also do this.
> 
> > into the "impressions" table of the db, a la "INSERT INTO
> > log
> Posted via http://www.ruby-forum.com/.
> 
> ```
> 
> >

NEW: Artprice Images(R): your access to past, present and upcoming  
auction catalogues from 2,900 auction houses worldwide and to the  
largest art auction library of 290,000 catalogues spanning from 1960 to  
the present days.

NOUVEAU: avec Artprice Images(R) accÃ©dez Ã tous les catalogues de ventes  
futures de 2 900 maisons de ventes et au plus grand fonds documentaire  
sur le marchÃ© de l’art avec 290 000 catalogues de vente de 1960 Ã nos  
jours.

NEU: Artprice Images(R) : Einsicht in sÃ¤mtliche Kataloge kommender  
Auktionen von weltweit 2.900 AuktionshÃ¤usern sowie in unser bis 1960  
zurÃ¼ckreichendes Archiv mit 290.000 Katalogen.

NUEVO: Artprice Images(R), acceda a todos los catÃ¡logos de las prÃ³ximas  
subastas de 2.900 subastadoras, y al fondo documentario mÃ¡s completo  
sobre el mercado del arte con 290.000 catÃ¡logos de subastas desde 1960  
hasta el dÃ­a de hoy.

NUOVO: Artprice Images(R) le permetterÃ di accedere a tutti i cataloghi  
delle vendite future delle 2.900 case d’aste e proporrÃ il piÃº  
importante fondo documentario sul mercato dell’arte grazie ali 290.000  
cataloghi di vendita dal 1960 ad oggi.

“Ce message et toutes les piÃ¨ces jointes sont des informations  
strictement confidentielles et rÃ©servÃ©es au(x) destinataire(s). Ce  
courriel n’a pas de valeur contractuelle et son contenu ne constitue ni  
une acceptation, ni un engagement de la part de l’auteur et des sociÃ©tÃ©s  
du groupe Serveur et Artprice, sauf dans le cas oÃ¹ cela aurait Ã©tÃ© prÃ©vu  
avec le destinataire par un accord Ã©crit. Le contenu de ce message et  
les piÃ¨ces jointes ne peuvent constituer une preuve au sens de l’article  
1316-1 du Code Civil. L’auteur et les sociÃ©tÃ©s du groupe Serveur et  
Artprice dÃ©clinent toute responsabilitÃ© au titre de ce courriel s’il a  
Ã©tÃ© altÃ©rÃ©, dÃ©formÃ©, falsifiÃ© ou indÃ»ment utilisÃ© par des tiers ou  
encore s’il a causÃ© tout dommage ou perte de toute nature. Si vous  
n’Ãªtes pas le bon destinataire, merci de nous contacter et de ne pas le  
divulguer.”

“This message including any attachments are confidential and privileged  
material intended solely for the addressees. Its contents do not  
constitute a commitment by groupe Serveur sas and Artprice SA, except  
when provided for in a written agreement with the addressees. The  
contents of this message cannot constitute neither the proof nor the  
acceptance of any agreement as per article 1316-1 of the French civil  
code.  
Groupe Serveur sas and Artprice SA shall not be rendered liable in any  
manner whatsoever for the delay and/or loss in transit of this message,  
for corruption, alteration, falsification, misuse or fraudulent use  
(which may be made) of this message. If you receive this message in  
error, please delete it and immediately notify the sender. If the reader  
of this message is not the intended recipient, you are hereby notified  
that any unauthorized use, copying or dissemination is prohibited.”
