rhttp.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * rhttp.c - simple HTTP transaction latency test
  3. *
  4. * usage: rhttp hostname [port] remote-clients -p file file
  5. *
  6. * This turns into a bunch of
  7. * rsh remote http hostname file file file [port]
  8. * with the results aggragated and reported.
  9. *
  10. * The program "http" must be in your path on the remote machine.
  11. *
  12. * XXX - the way this should work is like so:
  13. * parent process reading file names from stdin
  14. * multiple child processes connected to the parent process
  15. * while more file names
  16. * wait for a child process to be idle
  17. * feed it ~10 filenames
  18. * the child processes need to be able to tell the parent that they
  19. * want more work. They also need to pass back the results.
  20. *
  21. * Copyright (c) 1994-1997 Larry McVoy. Distributed under the FSF GPL with
  22. * additional restriction that results may published only if
  23. * (1) the benchmark is unmodified, and
  24. * (2) the version in the sccsid below is included in the report.
  25. * Support for this development by Silicon Graphics is gratefully acknowledged.
  26. */
  27. char *id = "$Id$\n";
  28. #include "bench.h"
  29. int
  30. main(int ac, char **av)
  31. {
  32. char *name = av[0], *server, *prog;
  33. int i, j;
  34. uint64 total = 0;
  35. uint64 usecs = 0;
  36. char *args[1024];
  37. if (ac < 5) {
  38. usage: fprintf(stderr,
  39. "Usage: %s hostname [port] remote-clients -p file ...\n",
  40. name);
  41. exit(1);
  42. }
  43. server = av[1];
  44. av++, ac--; /* eat server */
  45. if (atoi(av[1]) != 0) {
  46. prog = av[1];
  47. av++, ac--; /* eat port */
  48. } else {
  49. prog = "80"; /* http */
  50. }
  51. for (i = 1; i < ac; ++i) {
  52. if (!strcmp("-p", av[i])) {
  53. i++;
  54. break;
  55. }
  56. }
  57. args[0] = "rsh";
  58. args[2] = "http";
  59. args[3] = server;
  60. j = 4;
  61. while (i < ac) {
  62. args[j++] = av[i++];
  63. }
  64. args[j++] = prog;
  65. args[j] = 0;
  66. for (i = 1; i < ac; ++i) {
  67. if (!strcmp("-p", av[i])) {
  68. break;
  69. }
  70. args[1] = av[i];
  71. for (j = 0; args[j]; j++) {
  72. printf("%s ", args[j]);
  73. }
  74. printf("\n");
  75. if (fork() == 0) {
  76. char name[30];
  77. sprintf(name, "/tmp/rhttp%d", i);
  78. creat(name, 0666);
  79. close(2);
  80. dup(1);
  81. execvp(args[0], args);
  82. perror(args[0]);
  83. exit(1);
  84. }
  85. }
  86. for (i = 1; i < ac; ++i) {
  87. if (!strcmp("-p", av[i])) {
  88. break;
  89. }
  90. wait(0);
  91. }
  92. system("cat /tmp/rhttp*; rm /tmp/rhttp*");
  93. exit(1);
  94. for (i = 1; i < ac; ++i) {
  95. int fd, n, m = 0;
  96. float f1 = 0, f2 = 0;
  97. char buf[30];
  98. if (!strcmp("-p", av[i])) {
  99. break;
  100. }
  101. sprintf(buf, "/tmp/http%d", i);
  102. fd = open(buf, 0);
  103. unlink(buf);
  104. /*
  105. * Avg xfer: 3.9KB, 235.0KB in 2038 millisecs, 115.31 KB/sec
  106. */
  107. n = read(fd, buf, XFERSIZE);
  108. buf[n] = 0;
  109. sscanf(buf, "Avg xfer: %fKB, %fKB in %d millisecs,",
  110. &f1, &f2, &m);
  111. if (m > usecs) {
  112. usecs = m;
  113. }
  114. total += f2;
  115. }
  116. total <<= 10;
  117. usecs *= 1000;
  118. settime(usecs);
  119. latency((uint64)1, total);
  120. }