Comments (2)
I stayed away from workers due to limitations with the IPC layer. A few things the author has noted:
If you spend too much time polling in each iteration the rest of your daemon will suffer. So, try not spend more than 1 second at a time in the execute loop.
One thing to be aware of. The daemon is not really meant for high-speed processing. The 'calling' mechanism in the back-end that communicates with sub-processes can sometimes break if you make too many calls too quickly. A few messages per second is fine, but hundreds per second will start to become unstable, most likely. I've never tested how much I could do within workers.
Looking at your logs, I think you're encountering those limitations:
DEBUG: Daemon::wait: Loop took too long.
I'm not sure if it'll help your situation, but have you considered using tasks instead of workers? Tasks are the same thing, only they don't communicate back to the main daemon process thereby avoiding the IPC bottleneck entirely. They are fire and forget.
In my use case, I've got 5 daemons running, each one monitors various azure queues and fires off various processes (tasks) when there are messages in a queue. Each task runs as its own process in linux -- they exit gracefully and I have been hammering these daemons pretty hard. I can process hundreds of messages per second using this approach and its been super stable.
Just gotta make sure you keep the execute() logic light and have your tasks do all the heavy lifting. I process multiple message per task before letting that task exit -- just so im not spawning a process for every single message a queue.
Example:
/**
* Main application logic.
* Called every loop cycle
**/
protected function execute()
{
# broadcast a heartbeat every 5 minutes (based on run interval)
if ($this->getLoopIterations() % 60 == 0) {
$this->log("service status: okay");
}
try {
# get order queue counts
$createCount = AzureQ::queueCount('shopify-create');
$ordersCount = AzureQ::queueCount('shopify-orders');
} catch (Exception $e) {
return;
}
# kick off appropriate processor
if ($createCount > 0) { $this->task('OrderCreate'); }
if ($ordersCount > 0) { $this->task('OrderProcess'); }
}
use Lifo\Daemon\Task\AbstractTask;
class OrderProcess extends AbstractTask
{
# easy access to the daemon logging routines
# so we don't have to use Daemon::getInstance()->log
use \Lifo\Daemon\LogTrait;
public function run()
{
#do stuff
}
from php-daemon.
nothing i can do with this right now.
from php-daemon.
Related Issues (20)
- Documentation HOT 5
- Worker and pcntl_exec support HOT 9
- Forking Exception: Can't find PDO driver HOT 1
- Arguments to Tasks HOT 4
- How to write unit tests with your daemon? HOT 3
- what happens if a loop is still executing when the interval comes up? HOT 6
- Memory leak in workers HOT 17
- Logging Failure after Restart HOT 1
- Premature worker death HOT 1
- Method returns current worker proc count? HOT 1
- Parameters on Task->run causing Fatal Error HOT 2
- Daemon Restart Event Hook HOT 3
- Using callable in worker initialization HOT 2
- Possible memory leak HOT 2
- Where to catch Premature worker death and processed it HOT 3
- PHP 8.x HOT 2
- Use with MQTT Server
- How do I pass variables to workers/tasks? HOT 1
- Sysv Error: Error fetching message from queue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-daemon.