Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
So, at work we recently embarked on a quest to kill off long-running database queries by web worker processes whose clients have closed their browser tab, or likewise clicked a cancel button attached to their AJAX request. The main problem was that the whole backend is blocking-style, using a preforked Plack server, and there was no way to monitor for events on the socket while the database query was in progress. (nor did the Plack server even provide access to the socket) While the correct way is to use nonblocking queries and an event-loop webserver, that scale of a rewrite is not practical. Another possible option is to alter an existing plack server with fancy hooks to kill a query, but again, the single-threaded nature of the code prevents a lot of this.

Well, believe it or not, we actually managed to accomplish this feat with the existing app and Plack server using an Inline::C pthread and PadWalker and shelling out to run mysql -e 'kill $conn_id' and some other insanity, but IT WORKS!

To celebrate this achievement, I would like to bundle it up in a CPAN module. The main goal is to abort/kill/cancel everything a single-threaded web worker is doing (in a highly configurable manner, of course) whenever we lose the ability to reply to the requestor. The best name I have so far is IO::SocketStatusSignaler IO::SocketStatusTrigger IO::SocketAlarm. Anyone have other ideas?

I'm also happy to entertain conversations about less-insane methods for solving this problem.

Update:

API Preview:

# When the client goes away, terminate the current process # and also kill the mysql query that is running on the server. my $watch= watch_socket( socket => $socket, event => EVENT_EOF|EVENT_EPIPE, actions => [ [ run => 'mysql', -e => "kill $id" ], [ kill => $$, SIGKILL ], ] );

In reply to Naming a CPAN module that watches for closed sockets by NERDVANA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others sharing their wisdom with the Monastery: (6)
    As of 2024-09-09 15:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.