Skip to content

Execute jobs via php-fpm rather than forking #76

Open
@ebernhardson

Description

@ebernhardson

After a discussion with a co-worker i decided to write up a quick hack which executes jobs over php5-fpm instead of forking. This provides all the same protections as forking in regards to failures while reducing job execution overhead and providing a more natural php execution environment(vs fork). The Resque_Worker::fork method was adjusted to always return false when running the fastcgi tests.

This is just a POC, not intended for usage outside benchmarking but i think it shows promise.

https://gist.github.com/4253706

Initial benchmarks on an intel i5-2500k (4 cores no HT), ubuntu 12.04, php 5.4.8

WITH FORK:

COUNT=1 INTERVAL=0.01 QUEUE=default APP_INCLUDE=examples/worker_include.php php vendor/.../resque.php
1 Worker, no arguments
Completed 2000 jobs in 9.704s ~4.8ms per job per core
Completed 2000 jobs in 9.960s
Completed 2000 jobs in 10.014s
Completed 2000 jobs in 10.022s
Completed 2000 jobs in 10.000s
Completed 2000 jobs in 9.992s
Completed 2000 jobs in 10.310s
Completed 2000 jobs in 9.991s
Completed 2000 jobs in 10.002s
Completed 2000 jobs in 10.016s

COUNT=4 INTERVAL=0.01 QUEUE=default APP_INCLUDE=examples/worker_include.php php vendor/.../resque.php
4 Workers, no arguments, ~6.4ms per job per core
Completed 2000 jobs in 3.235s
Completed 2000 jobs in 3.250s
Completed 2000 jobs in 3.252s
Completed 2000 jobs in 3.247s
Completed 2000 jobs in 3.278s
Completed 2000 jobs in 3.282s
Completed 2000 jobs in 3.298s
Completed 2000 jobs in 3.292s
Completed 2000 jobs in 3.297s
Completed 2000 jobs in 3.304s

WITH FASTCGI:

COUNT=1 INTERVAL=0.01 QUEUE=default APP_INCLUDE=examples/worker_fcgi_include.php php vendor/.../resque.php
1 worker, no arguments
Completed 2000 jobs in 3.082s ~1.5ms per job per core
Completed 2000 jobs in 3.098s
Completed 2000 jobs in 3.102s
Completed 2000 jobs in 3.084s
Completed 2000 jobs in 3.093s
Completed 2000 jobs in 3.081s
Completed 2000 jobs in 3.111s
Completed 2000 jobs in 3.098s
Completed 2000 jobs in 3.101s
Completed 2000 jobs in 3.079s

COUNT=4 INTERVAL=0.01 QUEUE=default APP_INCLUDE=examples/worker_fcgi_include.php php vendor/.../resque.php
4 workers, no arguments
Completed 2000 jobs in 0.982s ~1.9ms per job per core
Completed 2000 jobs in 0.981s
Completed 2000 jobs in 0.988s
Completed 2000 jobs in 0.988s
Completed 2000 jobs in 0.989s
Completed 2000 jobs in 0.995s
Completed 2000 jobs in 0.987s
Completed 2000 jobs in 0.996s
Completed 2000 jobs in 0.983s
Completed 2000 jobs in 0.986s

To summarize:

FORK one core: 4.8ms/job/core four cores: 6.4ms/job/core
FASTCGI one core: 1.5ms/job/core four cores: 1.9ms/job/core

Naturally this is a synthetic benchmark with the actual job doing nothing. It is intended only to measure the amount of overhead involved in starting resque jobs. Additionally this was run over the loopback interface, as the provided FCGIClient class does not support unix sockets. It is unknown at this point how much overhead there is between tcp and unix sockets for our usage.

Thoughts? Would there be any interest in flushing out to a proper implementation?

EDIT: fixed bad math, 4 * 0.982/2000 makes for 1.9ms/job/core on 4 core fastcgi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions