MacOS Xã®fork/execãé ã件ã«ã¤ãã¦
ãªããã*1ã ãããlibtaskとPthreadの比較ãã§è»½ã触ãããMacOS Xã®forkãé ã件ã«ã¤ãã¦ããå°ã調ã¹ã¦ã¿ãã
åå使ã£ãããã°ã©ã ã¯ãããªæãã®ãã®ã
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> enum { ITER = 100 }; void do_fork(void) { pid_t pid; switch (pid = fork()) { case -1: perror("fork"); exit(1); case 0: /* child */ exit(1); default: while (wait(0) != pid); } } int main(int argc, char **argv) { int i; struct timeval tv; double begin, end; gettimeofday(&tv, NULL); begin = tv.tv_sec + tv.tv_usec * 1e-6; for (i = 0; i < ITER; i++) { do_fork(); } gettimeofday(&tv, NULL); end = tv.tv_sec + tv.tv_usec * 1e-6; printf("%g\n", (end - begin) / ITER); return 0; }
ä»åã¯ãBYTE UNIX Benchmark 4.1.0ã®ã·ã¹ãã ãã³ããã¼ã¯ã§æ¯è¼ãã¦ã¿ãã
MacOS X 10.4ãCore 2 Duo/2.0GHzã®å ´åã
TEST BASELINE RESULT INDEX Execl Throughput 188.3 435.8 23.1 File Copy 1024 bufsize 2000 maxblocks 2672.0 48484.0 181.5 File Copy 256 bufsize 500 maxblocks 1077.0 13844.0 128.5 File Read 4096 bufsize 8000 maxblocks 15382.0 315259.0 205.0 Pipe Throughput 111814.6 439237.6 39.3 Pipe-based Context Switching 15448.6 107754.3 69.8 Process Creation 569.3 887.4 15.6 Shell Scripts (8 concurrent) 44.8 270.5 60.4 System Call Overhead 114433.5 277117.6 24.2 ========= FINAL SCORE 57.5
Linux CentOS 5.2ãPentium 4/3.0GHz dualã®å ´åã
TEST BASELINE RESULT INDEX Execl Throughput 188.3 3692.7 196.1 File Copy 1024 bufsize 2000 maxblocks 2672.0 59336.0 222.1 File Copy 256 bufsize 500 maxblocks 1077.0 16637.0 154.5 File Read 4096 bufsize 8000 maxblocks 15382.0 619832.0 403.0 Pipe Throughput 111814.6 538893.8 48.2 Pipe-based Context Switching 15448.6 134891.3 87.3 Process Creation 569.3 11984.3 210.5 Shell Scripts (8 concurrent) 44.8 672.0 150.0 System Call Overhead 114433.5 592053.3 51.7 ========= FINAL SCORE 138.4
ãã¯ãexeclã¹ã«ã¼ãããã§8.3åãããã»ã¹çæã§13.5åãæ§è½å·®ãããããã¼ãã¦ã§ã¢ãå ¨ãéãã®ã§ãä¸æ¦ã«æ¯è¼ã§ããªãããã·ã¹ãã ã³ã¼ã«èªä½ã®ãªã¼ããããã2.1åãªã®ã§ãfork/execã¯æããã«é ãã¨ãããã
ã¨ãããã¨ã§ãktraceã使ã£ã¦å®è¡æéããã¬ã¼ã¹ãã¦ã¿ãã
$ ktrace ./bench.fork $ kdump -R -f ktrace.out
wait4ãå¼åºãã¦ããæ»ãã¾ã§ï¼ktraceã®ãªã¼ããããã§é ããªã£ã¦ãããï¼3ããªç§è¿ãããã£ã¦ãããããã¯wait4ã«å¦çæéãé£ã£ã¦ããããã§ã¯ãªãããã®éã«åããã»ã¹ãåãã¦ããã®ã ãããããªããããªã«æéããããã®ãããã£ã±ãããããããªãã
9775 bench.fork 0.000442 CALL fork 9775 bench.fork 0.000119 RET fork 9776/0x2630 9775 bench.fork 0.000119 CALL wait4(0xffffffff,0,0,0) 9775 bench.fork 0.003081 RET wait4 9776/0x2630
ããããä»ã®ããã»ã¹ã®å½±é¿ã極åãªãããã¨ãã·ã³ã°ã«ã¦ã¼ã¶ã¢ã¼ã*2ã§æ¸¬å®ãã¦ã¿ããexeclã¹ã«ã¼ãããã¯435.8 lpsãã828.0 lpsãããã»ã¹çæã¯887.4 lpsãã1856.8 lpsã¨ã2ååå¾æ¹åãããããã§ãé ããªãã