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 I'm also happy to entertain conversations about less-insane methods for solving this problem. Update: API Preview:
In reply to Naming a CPAN module that watches for closed sockets by NERDVANA
|
|