Stopping gearman workers nicely

后端 未结 12 857
滥情空心
滥情空心 2021-01-30 04:24

I have a number of Gearman workers running constantly, saving things like records of user page views, etc. Occasionally, I\'ll update the PHP code that is used by the Gearman w

12条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 04:53

    Solution 1


    Generally I run my workers with the unix daemon utility with the -r flag and let them expire after one job. Your script will end gracefully after each iteration and daemon will restart automatically.

    Your workers will be stale for one job but that may not be as big a deal to you as losing data

    This solution also has the advantage of freeing up memory. You may run into problems with memory if you're doing large jobs as PHP pre 5.3 has god awful GC.

    Solution 2


    You could also add a quit function to all of your workers that exits the script. When you'd like to restart you simply give gearman calls to quit with a high priority.

提交回复
热议问题