Changeset 04b73b6 for benchmark/io/http/main.cfa
- Timestamp:
- Jul 23, 2020, 3:37:05 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- f4ec4a90
- Parents:
- f0c3120 (diff), e262b5e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
benchmark/io/http/main.cfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
rf0c3120 r04b73b6 17 17 #include "filecache.hfa" 18 18 #include "options.hfa" 19 #include "parseargs.hfa"20 19 #include "worker.hfa" 21 20 … … 23 22 // Globals 24 23 //============================================================================================= 25 Options options @= {26 0,27 42u,28 0,29 false,30 false,31 032 };33 34 24 channel & wait_connect; 35 25 … … 39 29 40 30 void ?{}( ServerProc & this ) { 41 /* paranoid */ assert( options. the_cluster!= 0p );42 (this.self){ "Benchmark Processor", *options. the_cluster};31 /* paranoid */ assert( options.clopts.instance != 0p ); 32 (this.self){ "Benchmark Processor", *options.clopts.instance }; 43 33 44 34 #if !defined(__CFA_NO_STATISTICS__) 45 if( options. procstats ) {46 print_stats_at_exit( this.self, options. the_cluster->print_stats );35 if( options.clopts.procstats ) { 36 print_stats_at_exit( this.self, options.clopts.instance->print_stats ); 47 37 } 48 if( options. viewhalts ) {38 if( options.clopts.viewhalts ) { 49 39 print_halts( this.self ); 50 40 } … … 56 46 //=============================================================================================' 57 47 int main( int argc, char * argv[] ) { 58 int port = 8080;59 int backlog = 10;60 int nprocs = 1;61 int nworkers = 1;62 int cl_flags = 0;63 int chan_size = 10;64 const char * path = ".";65 48 //=================== 66 49 // Parse args 67 static cfa_option opt[] = { 68 {'p', "port", "Port the server will listen on", port}, 69 {'c', "cpus", "Number of processors to use", nprocs}, 70 {'t', "threads", "Number of worker threads to use", nworkers}, 71 {'b', "accept-backlog", "Maximum number of pending accepts", backlog}, 72 {'B', "channel-size", "Maximum number of accepted connection pending", chan_size} 73 }; 74 int opt_cnt = sizeof(opt) / sizeof(cfa_option); 75 76 char **left; 77 parse_args( argc, argv, opt, opt_cnt, "[OPTIONS] [PATH] -- cforall http server", left ); 78 50 const char * path = parse_options(argc, argv); 79 51 80 52 //=================== … … 85 57 //=================== 86 58 // Open Socket 87 printf("Listening on port %d\n", port);59 printf("Listening on port %d\n", options.socket.port); 88 60 int server_fd = socket(AF_INET, SOCK_STREAM, 0); 89 61 if(server_fd < 0) { … … 97 69 address.sin_family = AF_INET; 98 70 address.sin_addr.s_addr = htonl(INADDR_ANY); 99 address.sin_port = htons( port );71 address.sin_port = htons( options.socket.port ); 100 72 101 73 ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) ); … … 104 76 } 105 77 106 ret = listen( server_fd, backlog );78 ret = listen( server_fd, options.socket.backlog ); 107 79 if(ret < 0) { 108 80 abort( "listen error: (%d) %s\n", (int)errno, strerror(errno) ); … … 112 84 // Run Server Cluster 113 85 { 114 cluster cl = { "Server Cluster", cl_flags };86 cluster cl = { "Server Cluster", options.clopts.flags }; 115 87 #if !defined(__CFA_NO_STATISTICS__) 116 88 print_stats_at_exit( cl, CFA_STATS_READY_Q | CFA_STATS_IO ); 117 89 #endif 118 options. the_cluster= &cl;90 options.clopts.instance = &cl; 119 91 120 channel chan = { chan_size };92 channel chan = { options.clopts.chan_size }; 121 93 &wait_connect = &chan; 122 94 95 int pipe_cnt = options.clopts.nworkers * 2; 96 int pipe_off; 97 int * fds; 98 [fds, pipe_off] = filefds( pipe_cnt ); 99 for(i; 0 ~ pipe_cnt ~ 2) { 100 int ret = pipe(&fds[pipe_off + i]); 101 if( ret < 0 ) { abort( "pipe error: (%d) %s\n", (int)errno, strerror(errno) ); } 102 } 103 123 104 { 124 ServerProc procs[ nprocs];105 ServerProc procs[options.clopts.nprocs]; 125 106 { 126 Worker workers[nworkers]; 127 printf("%d workers started on %d processors\n", nworkers, nprocs); 107 Worker workers[options.clopts.nworkers]; 108 for(i; options.clopts.nworkers) { 109 if( options.file_cache.fixed_fds ) { 110 workers[i].pipe[0] = pipe_off + (i * 2) + 0; 111 workers[i].pipe[1] = pipe_off + (i * 2) + 1; 112 } 113 else { 114 workers[i].pipe[0] = fds[pipe_off + (i * 2) + 0]; 115 workers[i].pipe[1] = fds[pipe_off + (i * 2) + 1]; 116 } 117 unpark( workers[i] __cfaabi_dbg_ctx2 ); 118 } 119 printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs); 128 120 { 129 121 Acceptor acceptor = { server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen, 0 }; 122 123 char buffer[128]; 124 while(!feof(stdin)) { 125 fgets(buffer, 128, stdin); 126 } 127 128 printf("Shutting Down\n"); 130 129 } 131 printf(" Shutting Down\n");130 printf("Acceptor Closed\n"); 132 131 133 132 // Clean-up the workers 134 for( nworkers) {133 for(options.clopts.nworkers) { 135 134 put( wait_connect, -1 ); 136 135 } 137 136 } 137 printf("Workers Closed\n"); 138 138 } 139 140 for(i; pipe_cnt) { 141 ret = close( fds[pipe_off + i] ); 142 if(ret < 0) { 143 abort( "close pipe error: (%d) %s\n", (int)errno, strerror(errno) ); 144 } 145 } 146 free(fds); 139 147 } 140 148
Note:
See TracChangeset
for help on using the changeset viewer.