40 #include <sys/types.h>
46 #include <sys/socket.h>
48 #include <sys/resource.h>
61 static int count, writes, fired;
63 static int num_pipes, num_active, num_writes;
64 static struct event *events;
67 read_cb(
int fd,
short which,
void *arg)
69 long idx = (long) arg, widx = idx + 1;
72 count += read(fd, &ch,
sizeof(ch));
74 if (widx >= num_pipes)
76 write(pipes[2 * widx + 1],
"e", 1);
89 for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
90 event_del(&events[i]);
91 event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (
void *) i);
92 event_add(&events[i], NULL);
98 space = num_pipes / num_active;
100 for (i = 0; i < num_active; i++, fired++)
101 write(pipes[i * space + 1],
"e", 1);
106 gettimeofday(&ts, NULL);
110 }
while (count != fired);
111 gettimeofday(&te, NULL);
113 if (xcount != count) fprintf(stderr,
"Xcount: %d, Rcount: %d\n", xcount, count);
116 evutil_timersub(&te, &ts, &te);
122 main (
int argc,
char **argv)
133 num_writes = num_pipes;
134 while ((c = getopt(argc, argv,
"n:a:w:")) != -1) {
137 num_pipes = atoi(optarg);
140 num_active = atoi(optarg);
143 num_writes = atoi(optarg);
146 fprintf(stderr,
"Illegal argument \"%c\"\n", c);
152 rl.rlim_cur = rl.rlim_max = num_pipes * 2 + 50;
153 if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
159 events = calloc(num_pipes,
sizeof(
struct event));
160 pipes = calloc(num_pipes * 2,
sizeof(
int));
161 if (events == NULL || pipes == NULL) {
168 for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
170 if (pipe(cp) == -1) {
172 if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
179 for (i = 0; i < 25; i++) {
183 fprintf(stdout,
"%ld\n",
184 tv->tv_sec * 1000000L + tv->tv_usec);