I'd like to try to stress-test a PHP script I've written, which accesses the filesystem, to see how it copes with load and parallel access.

I'd like to run this script x times in y different processes parallelly.

Is there a tool for this?

  • 4
    echo {0..$x} | xargs -n 1 -P $y php yourscript.php might be a start – frostschutz Jul 16 '13 at 13:04
  • @frostschutz Excellent, thanks. Can you add this as an answer? – Benjamin Jul 16 '13 at 13:08
  • 1
    There is also parallel from moreutils. – derobert Jul 16 '13 at 15:44

xargs allows easy parallel processing. Here is an example (which assumes that your version of xargs supports the -0 switch, which is not a POXIX requirement. If portability is an issue, simply use echo and drop the -0).

printf '%s\0' {1..$maxruns} | xargs -0 -I, -n 1 -P $instances <program>

printf outputs the numbers from 1 to 2000 delimited by NULL characters. This is piped to xargs. The -0 option notifies xargs that the values are delimited by a NULL characters instead of whitespace. The -I switch replaces the following character (a comma, can be any character sequence) with the input value. Since the input values are the numbers, which we don't need, and there is no other comma in the command line, the input is simply discarded. -n 1 provides a maximum of one argument to <program>. -P 50 runs no more than 50 instances of <program> at a time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.