pilat
254
2
Laravel

Coding efficient jobs

Posted 6 months ago by pilat

Recently, I've moved from queue:listen to queue:work, because the project consumes lots of resources on doing its main job (like syncing between external API and local DB, processing webhooks, many scheduled tasks), so, spending even more resources on bootstrapping… I don't know.

The "hacky" point, however, is that daemonized job may leak memory. So, my questions is: how do I make sure that the memory is not leaked in my jobs?

  • How can I detect a memory is leaked (without horizon; I'm on Laravel 5.3 now)
  • What should I care about, when writing jobs? Should I explicitly close DB connection, for instance? Or, does Laravel do it for me? Should I close cache file's handlers (I'm using CACHE_DRIVER=file) manually? Should I null all used variables? etc. It's just a "grey area" for me, because I'm only used to write "response rapidly and die quick" kind of code :-(
  • Is there a good guide on how to write Laravel jobs specifically for daemon runner?

2nd point: I'm also thinking about all that "full-blooded boots" when the only thing, that is expected from controller — is dispatching a job (e.g., processing a webhook). Maybe, there's a solution to put a new job into queue (I'm using DB driver for jobs) without loading Laravel? I'm thinking of a stand-alone PHP script with very little footprint here.

Please sign in or create an account to participate in this conversation.