Changeset 2ecbd7b for benchmark/io/http/main.cfa
- Timestamp:
- Jul 17, 2020, 5:39:26 PM (3 years ago)
- Branches:
- ADT, arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e95a117
- Parents:
- 0d52c6f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
r0d52c6f r2ecbd7b 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, // open_flags;27 42u, // hash_seed;28 0, // file_cache_size;29 false, // file_cache_list;30 false, // procstats;31 false, // viewhalts;32 0 // the_cluster;33 };34 35 24 channel & wait_connect; 36 25 … … 40 29 41 30 void ?{}( ServerProc & this ) { 42 /* paranoid */ assert( options. the_cluster!= 0p );43 (this.self){ "Benchmark Processor", *options. the_cluster};31 /* paranoid */ assert( options.clopts.instance != 0p ); 32 (this.self){ "Benchmark Processor", *options.clopts.instance }; 44 33 45 34 #if !defined(__CFA_NO_STATISTICS__) 46 if( options. procstats ) {47 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 ); 48 37 } 49 if( options. viewhalts ) {38 if( options.clopts.viewhalts ) { 50 39 print_halts( this.self ); 51 40 } … … 57 46 //=============================================================================================' 58 47 int main( int argc, char * argv[] ) { 59 int port = 8080;60 int backlog = 10;61 int nprocs = 1;62 int nworkers = 1;63 int cl_flags = 0;64 int chan_size = 10;65 const char * path = ".";66 48 //=================== 67 49 // Parse args 68 static cfa_option opt[] = { 69 {'p', "port", "Port the server will listen on", port}, 70 {'c', "cpus", "Number of processors to use", nprocs}, 71 {'t', "threads", "Number of worker threads to use", nworkers}, 72 {'b', "accept-backlog", "Maximum number of pending accepts", backlog}, 73 {'B', "channel-size", "Maximum number of accepted connection pending", chan_size}, 74 {'S', "seed", "seed to use for hashing", options.hash_seed }, 75 {'C', "cache-size", "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache_size }, 76 {'l', "list-files", "List the files in the specified path and exit", options.file_cache_list, parse_settrue } 77 78 }; 79 int opt_cnt = sizeof(opt) / sizeof(cfa_option); 80 81 char **left; 82 parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left ); 83 if( left[0] != 0p ) { 84 path = left[0]; 85 left++; 86 } 87 if( left[0] != 0p ) { 88 abort("Too many trailing arguments!\n"); 89 } 90 50 const char * path = parse_options(argc, argv); 91 51 92 52 //=================== … … 97 57 //=================== 98 58 // Open Socket 99 printf("Listening on port %d\n", port);59 printf("Listening on port %d\n", options.socket.port); 100 60 int server_fd = socket(AF_INET, SOCK_STREAM, 0); 101 61 if(server_fd < 0) { … … 109 69 address.sin_family = AF_INET; 110 70 address.sin_addr.s_addr = htonl(INADDR_ANY); 111 address.sin_port = htons( port );71 address.sin_port = htons( options.socket.port ); 112 72 113 73 ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) ); … … 116 76 } 117 77 118 ret = listen( server_fd, backlog );78 ret = listen( server_fd, options.socket.backlog ); 119 79 if(ret < 0) { 120 80 abort( "listen error: (%d) %s\n", (int)errno, strerror(errno) ); … … 124 84 // Run Server Cluster 125 85 { 126 cluster cl = { "Server Cluster", cl_flags };86 cluster cl = { "Server Cluster", options.clopts.flags }; 127 87 #if !defined(__CFA_NO_STATISTICS__) 128 88 print_stats_at_exit( cl, CFA_STATS_READY_Q | CFA_STATS_IO ); 129 89 #endif 130 options. the_cluster= &cl;90 options.clopts.instance = &cl; 131 91 132 channel chan = { chan_size };92 channel chan = { options.clopts.chan_size }; 133 93 &wait_connect = &chan; 134 94 135 95 { 136 ServerProc procs[ nprocs];96 ServerProc procs[options.clopts.nprocs]; 137 97 { 138 Worker workers[ nworkers];139 printf("%d workers started on %d processors\n", nworkers,nprocs);98 Worker workers[options.clopts.nworkers]; 99 printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs); 140 100 { 141 101 Acceptor acceptor = { server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen, 0 }; … … 144 104 145 105 // Clean-up the workers 146 for( nworkers) {106 for(options.clopts.nworkers) { 147 107 put( wait_connect, -1 ); 148 108 }
Note: See TracChangeset
for help on using the changeset viewer.