Created
December 3, 2013 21:20
-
-
Save zachallett/7777682 to your computer and use it in GitHub Desktop.
Load testing scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use threads; | |
| my $NUM_THREADS = 8; | |
| sub do_work { | |
| while() { | |
| my $a = rand + rand; | |
| } | |
| } | |
| for(1 .. $NUM_THREADS) { | |
| my $thr = threads->create(\&do_work); | |
| } | |
| for my $thr (threads->list()) { | |
| $thr->join(); | |
| } | |
| exit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env ruby | |
| # set equal to number of CPU cores | |
| NUMBER_OF_THREADS = 4 | |
| def load_test | |
| while(true) do | |
| rand(0..10000) + rand(0..10000) | |
| end | |
| end | |
| (1..NUMBER_OF_THREADS).each do |p| | |
| fork do | |
| puts "PID -> #{Process.pid}" | |
| load_test | |
| end | |
| end | |
| # Process.waitall waits for all children to return an exit status | |
| Process.waitall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment