On Thu, Jan 16, 2014 at 9:29 AM, Ben van Staveren
<[email protected]>wrote:
> Are there any tools to help pinpoint where blocking is occurring? For
>> example, when I wrote my first app connecting to a database, I had no
>> reason to suspect that the connection to the database is what was causing
>> the event loop to back up. Especially when I run a query on the mysql>
>> prompt and it tells me the query takes 0.00 seconds or 0.02 seconds at
>> most. The problem of course was when dozens of users were connecting to
>> the app and therefore the database concurrently and I had only a few
>> preforked processes at most.
>>
>
> Not really that I know of, it's just one of those things that after a
> while becomes a problem on the level of a missing ; somewhere, you
> generally will have a good idea of where it's at. The key is that you need
> to design your entire app top to bottom to use non-blocking, and generally
> if you've done that there are no places where you block without knowing it,
> only places where you block but for a very explicit reason (and sometimes
> that reason can be something as simple as "there is no non-blocking module
> that does what I need and I can't write one yet")
And part of designing your app top to bottom to use non-blocking is to
understand that different modules you use will or will not block. Often
easily evidenced by the fact that the Module's API expects a callback or
not.
For example,
$dbh->do("SELECT * FROM table");
will block for as long as do() takes to send the query to the database and
to get the response back from the database. There's no reason that code
execution would be able to continue beyond the do() until do() is done or
else why run the do() in the first place! The results would be
inaccessible. Likewise with connect() ... there's no reason to continue on
to the next code line when connect() isn't done because the next line might
be to read from the socket but it hasn't even connected yet!
Of course, you can't magically make connect() have a callback and call it
like connect(cb => sub { ... }) but you could choose a different module or
write your own implementation. In the case of connect() just use
Mojo::IOLoop->client instead. Of course, it's not intended to be a drop-in
replacement so some recoding will be necessary beyond changing
Socket::connect() to Mojo::IOLoop->client() :D
--
*----------------------------------------------------------------*
*Keystone IT made the following notation*
*----------------------------------------------------------------*
*Email Confidentiality Notice: The information contained in this
transmission is confidential, proprietary or privileged and may be subject
to protection under the law, including the Health Insurance Portability and
Accountability Act (HIPAA). *
*This message is for the sole use of the intended individual or entity to
whom it is addressed. If you are not the intended recipient, you are
notified that any use, distribution or copying of the message is strictly
prohibited and may subject you to criminal or civil penalties. If you
received this transmission in error, please contact the sender immediately
at (314) 621-9500 and delete the material from all computers.*
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/groups/opt_out.