source: benchmark/io/http/options.cfa @ 430ce61

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 430ce61 was 8c58e73, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Removed webserver feature to have multiple clusters (it never actually worked)

  • Property mode set to 100644
File size: 4.4 KB
Line 
1#include "options.hfa"
2
3#define _GNU_SOURCE
4#define __USE_GNU
5extern "C" {
6        #include <sys/types.h>
7        #include <sys/stat.h>
8        #include <fcntl.h>
9}
10
11#include <bitmanip.hfa>
12#include <fstream.hfa>
13#include <kernel.hfa>
14#include <parseargs.hfa>
15#include <stdlib.hfa>
16
17#include <stdlib.h>
18#include <string.h>
19
20Options options @= {
21        false, // log
22        false, // stats
23        true, // interactive
24        0, // redirect
25        0, // redirect
26
27        { // file_cache
28                0,     // path
29                0,     // open_flags;
30                42u,   // hash_seed;
31                0,     // size;
32                false, // list;
33                false  // fixed_fds
34        },
35
36        { // socket
37                8080,  // port
38                10,    // backlog
39                1024,  // buflen
40                false  // reuseport
41        },
42
43        { // cluster
44                1,     // nprocs;
45                1,     // nworkers;
46                {},     // params;
47                false, // procstats
48                false, // viewhalts
49                0,     // instance;
50        }
51};
52
53void parse_options( int argc, char * argv[] ) {
54        unsigned nentries = 0;
55        static cfa_option opt[] = {
56                { 'p', "port",           "Port the server will listen on", options.socket.port},
57                { 'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
58                { 't', "threads",        "Number of worker threads to use", options.clopts.nworkers},
59                {'\0', "log",            "Enable logs", options.log, parse_settrue},
60                {'\0', "sout",           "Redirect standard out to file", options.reopen_stdout},
61                {'\0', "serr",           "Redirect standard error to file", options.reopen_stderr},
62                {'\0', "stats",          "Enable statistics", options.stats, parse_settrue},
63                {'\0', "shell",          "Disable interactive mode", options.interactive, parse_setfalse},
64                {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
65                {'\0', "reuseport",      "Use acceptor threads with reuse port SO_REUSEPORT", options.socket.reuseport, parse_settrue},
66                {'\0', "request_len",    "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen},
67                {'\0', "seed",           "seed to use for hashing", options.file_cache.hash_seed },
68                {'\0', "cache-size",     "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
69                {'\0', "list-files",     "List the files in the specified path and exit", options.file_cache.list, parse_settrue },
70                // { 'f', "fixed-fds",      "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
71                // { 'k', "kpollsubmit",    "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
72                // { 'i', "kpollcomplete",  "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
73                {'e', "numentries",     "Number of I/O entries", nentries },
74
75        };
76        int opt_cnt = sizeof(opt) / sizeof(cfa_option);
77
78        char **left;
79        parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left );
80
81        if( nentries != 0 && !is_pow2(nentries) ) {
82                unsigned v = nentries;
83                v--;
84                v |= v >> 1;
85                v |= v >> 2;
86                v |= v >> 4;
87                v |= v >> 8;
88                v |= v >> 16;
89                v++;
90                serr | "Warning: num_entries not a power of 2" | '(' | nentries | ')' | "raising to " | v;
91                nentries = v;
92        }
93        options.clopts.params.num_entries = nentries;
94        options.clopts.instance = 0p;
95        options.clopts.thrd_cnt = 0;
96
97
98        // if( fixedfd ) {
99        //      options.file_cache.fixed_fds = true;
100        // }
101
102        // if( sqkpoll ) {
103        //      options.file_cache.fixed_fds = true;
104        // }
105
106        // if( iokpoll ) {
107        //      options.file_cache.open_flags |= O_DIRECT;
108        // }
109
110        if( left[0] == 0p ) { return; }
111
112        const char * path = left[0];
113        left++;
114
115        if( left[0] != 0p ) {
116                serr | "Too many trailing arguments!" | '\'' | path | '\'';
117                while(left[0] != 0p) {
118                        serr | " - " | left[0];
119                        left++;
120                }
121                exit(EXIT_FAILURE);
122        }
123
124        options.file_cache.path = path;
125
126        if( options.reopen_stdout && options.reopen_stderr && 0 == strcmp(options.reopen_stdout, options.reopen_stderr) ) {
127                serr | "Redirect sout and serr to the same file is not supported";
128                exit(EXIT_FAILURE);
129        }
130
131        if( options.reopen_stdout ) {
132                sout | "redirecting sout to '" | options.reopen_stdout | "'";
133                FILE  * ret = freopen( options.reopen_stdout, "w", stdout);
134                if( ret == 0p ) {
135                        serr | "Failed to redirect sout to '" | options.reopen_stdout | "'";
136                        exit(EXIT_FAILURE);
137                }
138        }
139
140        if( options.reopen_stderr ) {
141                sout | "redirecting serr to '" | options.reopen_stderr | "'";
142                FILE  * ret = freopen( options.reopen_stderr, "w", stderr);
143                if( ret == 0p ) {
144                        serr | "Failed to redirect serr to '" | options.reopen_stderr | "'";
145                        exit(EXIT_FAILURE);
146                }
147        }
148}
Note: See TracBrowser for help on using the repository browser.