Test Post

04/Feb/2015

Bottles of wine and poison

You have 1000 bottles of wine. One is poison. You have 10 mice. Each of the mice must drink at the same time. They can not be in sequence and you may not reuse mice that have drank. Thus, one shot to find the poison bottle. How do you distribute the wine such that you achieve this.

Threading in PHP

LAMP Stack: Do You Really Need Gearman?

Thoughts; If you are using a framework that supports CLI execution, couldn't you write a 100 line command line that bootstraps the framework through ubuntu upstart ( and monitors it for crashes ) that just polls a table and performs row locks? MySQL can handle thousands of requests per second and it's hardly performing the heavy lifting, the job servers are. So you could have master/slave for redundancy.

Need scheduling ?

CREATE EVENT $randomized

ON SCHEDULE AT CURRENT_TIMESTAMP + ( do math to get this: INTERVAL 1 HOUR )

DO

INSERT INTO queue values ( 'action', 'JSON/Serialized PARAMS' );

OPTIONALLY: repeat it every X

On the second your schedule cron comes due, you get a row in your queue and your job servers go to town. Already on a lamp stack? 100 lines and you've leveraged your stack to have a job server that can leverage everything you've written into your application without any external dependencies. Want visibility into your queue? Just write some code that reads these tables.

Ultimately, I like gearman, but I've gotten this to scale to 10,000 jobs a second in sandbox testing doing trivial tasks ( hell world ) with a mysql innodb table. It was really to demonstrate that MySQL could handle it. You leverage your existing stack without adding complexity by adding 2 more gearman servers ( HA ). More to come.