-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
119 lines (108 loc) · 4.26 KB
/
Copy pathmain.cc
File metadata and controls
119 lines (108 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @file main.cc
* @brief Entry point. Ignores SIGPIPE and starts the web_server event loop on port 8080.
*
* CSCI 599: Network Systems for Cloud Computing
* University of Southern California
*/
#include "web_server.hpp"
#include "log.hpp"
#include <memory>
#include <signal.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <cstdlib>
#include <cstring>
static void print_usage(const char* prog) {
fprintf(stderr, "Usage: %s [ewma|ewma_adaptive|reactive|static <N>|arima] [--no-cow]\n", prog);
fprintf(stderr, " ewma EWMA + CUSUM predictive pre-warming (default)\n");
fprintf(stderr, " ewma_adaptive EWMA + Standardized CUSUM (baseline-invariant)\n");
fprintf(stderr, " reactive Reactive baseline: scale to observed RPS only\n");
fprintf(stderr, " static <N> Static baseline: always maintain N warm workers\n");
fprintf(stderr, " arima ARIMA-based predictor\n");
fprintf(stderr, "\n");
fprintf(stderr, " --no-cow Disable the CoW template process. Each worker\n");
fprintf(stderr, " pays the full ~900ms Python+Pillow boot. Used\n");
fprintf(stderr, " for the CoW vs Predictor ablation (B4).\n");
}
int main(int argc, char* argv[]) {
// Prevent crashes when writing to a disconnected client
signal(SIGPIPE, SIG_IGN);
// Raise fd limit to handle long multi-cycle tests.
// Default is 1024; 4 cycles × ~600 requests can accumulate enough CLOSE-WAIT
// connections to exhaust it, causing accept() to fail with EMFILE.
{
struct rlimit rl;
getrlimit(RLIMIT_NOFILE, &rl);
rl.rlim_cur = 65536;
if (rl.rlim_max != RLIM_INFINITY && rl.rlim_cur > rl.rlim_max)
rl.rlim_cur = rl.rlim_max;
setrlimit(RLIMIT_NOFILE, &rl);
}
// Ensure log directory exists before logMessage() tries to open files
mkdir("logs", 0755);
// Parse mode + optional --no-cow flag.
// Accepted forms:
// ./server <mode>
// ./server static <N>
// ./server <mode> --no-cow
// ./server static <N> --no-cow
std::string mode = "ewma";
int static_n = 5;
bool use_cow_template = true;
int positional = 0; // count of non-flag args consumed beyond argv[0]
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--no-cow") {
use_cow_template = false;
continue;
}
// positional argument
if (positional == 0) {
mode = arg;
++positional;
} else if (positional == 1 && mode == "static") {
static_n = std::atoi(arg.c_str());
if (static_n <= 0) {
fprintf(stderr, "Error: static worker count must be > 0.\n");
return 1;
}
++positional;
} else {
fprintf(stderr, "Error: unexpected argument '%s'.\n", arg.c_str());
print_usage(argv[0]);
return 1;
}
}
if (mode == "static" && positional < 2) {
fprintf(stderr, "Error: 'static' mode requires a worker count argument.\n");
print_usage(argv[0]);
return 1;
}
if (mode != "ewma" && mode != "ewma_adaptive" && mode != "reactive"
&& mode != "arima" && mode != "static") {
fprintf(stderr, "Error: unknown mode '%s'.\n", mode.c_str());
print_usage(argv[0]);
return 1;
}
// Set log path based on mode and CoW state:
// logs/server_<mode>[_static_N][_nocow].log
std::string log_path = "logs/server_" + mode;
if (mode == "static") log_path += "_" + std::to_string(static_n);
if (!use_cow_template) log_path += "_nocow";
log_path += ".log";
SetLogPath(log_path);
logMessage(NORMAL, "===== Edge FaaS Gateway starting (port 8080) =====");
logMessage(NORMAL, "Logs -> %s", log_path.c_str());
if (mode == "static") {
logMessage(NORMAL, "Mode: static (N=%d)%s", static_n,
use_cow_template ? "" : " [CoW=OFF]");
} else {
logMessage(NORMAL, "Mode: %s%s", mode.c_str(),
use_cow_template ? "" : " [CoW=OFF]");
}
std::unique_ptr<fengcheng::web_server> svr(
new fengcheng::web_server(PORT, mode, static_n, use_cow_template));
svr->start();
return 0;
}