Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/main.cfa

    r53e4562 re95a117  
    1717#include "filecache.hfa"
    1818#include "options.hfa"
    19 #include "parseargs.hfa"
    2019#include "worker.hfa"
    2120
     
    2322// Globals
    2423//=============================================================================================
    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 
    3524channel & wait_connect;
    3625
     
    4029
    4130void ?{}( 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 };
    4433
    4534        #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 );
    4837                }
    49                 if( options.viewhalts ) {
     38                if( options.clopts.viewhalts ) {
    5039                        print_halts( this.self );
    5140                }
     
    5746//============================================================================================='
    5847int 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 = ".";
    6648        //===================
    6749        // 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);
    9151
    9252        //===================
     
    9757        //===================
    9858        // Open Socket
    99         printf("Listening on port %d\n", port);
     59        printf("Listening on port %d\n", options.socket.port);
    10060        int server_fd = socket(AF_INET, SOCK_STREAM, 0);
    10161        if(server_fd < 0) {
     
    10969        address.sin_family = AF_INET;
    11070        address.sin_addr.s_addr = htonl(INADDR_ANY);
    111         address.sin_port = htons( port );
     71        address.sin_port = htons( options.socket.port );
    11272
    11373        ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) );
     
    11676        }
    11777
    118         ret = listen( server_fd, backlog );
     78        ret = listen( server_fd, options.socket.backlog );
    11979        if(ret < 0) {
    12080                abort( "listen error: (%d) %s\n", (int)errno, strerror(errno) );
     
    12484        // Run Server Cluster
    12585        {
    126                 cluster cl = { "Server Cluster", cl_flags };
     86                cluster cl = { "Server Cluster", options.clopts.flags };
    12787                #if !defined(__CFA_NO_STATISTICS__)
    12888                        print_stats_at_exit( cl, CFA_STATS_READY_Q | CFA_STATS_IO );
    12989                #endif
    130                 options.the_cluster = &cl;
     90                options.clopts.instance = &cl;
    13191
    132                 channel chan = { chan_size };
     92                channel chan = { options.clopts.chan_size };
    13393                &wait_connect = &chan;
    13494
    13595                {
    136                         ServerProc procs[nprocs];
     96                        ServerProc procs[options.clopts.nprocs];
    13797                        {
    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);
    140100                                {
    141101                                        Acceptor acceptor = { server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen, 0 };
     102
     103                                        char buffer[128];
     104                                        while(!feof(stdin)) {
     105                                                fgets(buffer, 128, stdin);
     106                                        }
     107
     108                                        printf("Shutting Down\n");
    142109                                }
    143                                 printf("Shutting Down\n");
     110                                printf("Acceptor Closed\n");
    144111
    145112                                // Clean-up the workers
    146                                 for(nworkers) {
     113                                for(options.clopts.nworkers) {
    147114                                        put( wait_connect, -1 );
    148115                                }
    149116                        }
     117                        printf("Workers Closed\n");
    150118                }
    151119        }
Note: See TracChangeset for help on using the changeset viewer.