39#define TS_Xeq(key, func) NoGo = (strcmp(key, var) == 0) ? func(Config) : 0
44 XrdOucStream Config(&m_log, getenv(
"XRDINSTANCE"), &myEnv,
"(Throttle Config)> ");
46 if (config_file.empty()) {
47 m_log.Say(
"No filename specified.");
50 if ((cfgFD =
open(config_file.c_str(), O_RDONLY)) < 0) {
51 m_log.Emsg(
"Config", errno,
"Unable to open configuration file", config_file.c_str());
55 static const char *cvec[] = {
"*** throttle (ofs) plugin config:", 0 };
60 while( (var = Config.GetMyFirstWord()) )
62 if (!strcmp(
"throttle.fslib", var)) {
63 val = Config.GetWord();
64 if (!val || !val[0]) {m_log.Emsg(
"Config",
"fslib not specified.");
continue;}
67 TS_Xeq(
"throttle.max_open_files", xmaxopen);
68 TS_Xeq(
"throttle.max_active_connections", xmaxconn);
69 TS_Xeq(
"throttle.throttle", xthrottle);
70 TS_Xeq(
"throttle.loadshed", xloadshed);
71 TS_Xeq(
"throttle.max_wait_time", xmaxwait);
72 TS_Xeq(
"throttle.trace", xtrace);
75 m_log.Emsg(
"Config",
"Throttle configuration failed.");
97 auto val = Config.GetWord();
98 if (!val || val[0] ==
'\0')
99 {m_log.
Emsg(
"Config",
"Max open files not specified! Example usage: throttle.max_open_files 16000");}
100 long long max_open = -1;
101 if (
XrdOuca2x::a2sz(m_log,
"max open files value", val, &max_open, 1))
return 1;
103 m_max_open = max_open;
121Configuration::xmaxconn(XrdOucStream &Config)
123 auto val =
Config.GetWord();
124 if (!val || val[0] ==
'\0')
125 {m_log.Emsg(
"Config",
"Max active connections not specified! Example usage: throttle.max_active_connections 4000");}
126 long long max_conn = -1;
127 if (
XrdOuca2x::a2sz(m_log,
"max active connections value", val, &max_conn, 1))
return 1;
129 m_max_conn = max_conn;
148Configuration::xmaxwait(XrdOucStream &Config)
150 auto val =
Config.GetWord();
151 if (!val || val[0] ==
'\0')
152 {m_log.Emsg(
"Config",
"Max waiting time not specified (must be in seconds)! Example usage: throttle.max_wait_time 20");}
153 long long max_wait = -1;
154 if (
XrdOuca2x::a2sz(m_log,
"max waiting time value", val, &max_wait, 1))
return 1;
156 m_max_wait = max_wait;
177Configuration::xthrottle(XrdOucStream &Config)
179 long long drate = -1, irate = -1, rint = 1000, climit = -1;
182 while ((val =
Config.GetWord()))
184 if (strcmp(
"data", val) == 0)
186 if (!(val =
Config.GetWord()))
187 {m_log.Emsg(
"Config",
"data throttle limit not specified.");
return 1;}
188 if (
XrdOuca2x::a2sz(m_log,
"data throttle value",val,&drate,1))
return 1;
190 else if (strcmp(
"iops", val) == 0)
192 if (!(val =
Config.GetWord()))
193 {m_log.Emsg(
"Config",
"IOPS throttle limit not specified.");
return 1;}
194 if (
XrdOuca2x::a2sz(m_log,
"IOPS throttle value",val,&irate,1))
return 1;
196 else if (strcmp(
"rint", val) == 0)
198 if (!(val =
Config.GetWord()))
199 {m_log.Emsg(
"Config",
"recompute interval not specified (in ms).");
return 1;}
200 if (
XrdOuca2x::a2sp(m_log,
"recompute interval value (in ms)",val,&rint,10))
return 1;
202 else if (strcmp(
"concurrency", val) == 0)
204 if (!(val =
Config.GetWord()))
205 {m_log.Emsg(
"Config",
"Concurrency limit not specified.");
return 1;}
206 if (
XrdOuca2x::a2sz(m_log,
"Concurrency limit value",val,&climit,1))
return 1;
210 m_log.Emsg(
"Config",
"Warning - unknown throttle option specified", val,
".");
214 m_throttle_data_rate = drate;
215 m_throttle_iops_rate = irate;
216 m_throttle_concurrency_limit = climit;
217 m_throttle_recompute_interval_ms = rint;
237int Configuration::xloadshed(XrdOucStream &Config)
239 long long port = 0, freq = 0;
241 std::string hostname;
243 while ((val =
Config.GetWord()))
245 if (strcmp(
"host", val) == 0)
247 if (!(val =
Config.GetWord()))
248 {m_log.Emsg(
"Config",
"loadshed hostname not specified.");
return 1;}
251 else if (strcmp(
"port", val) == 0)
253 if (!(val =
Config.GetWord()))
254 {m_log.Emsg(
"Config",
"Port number not specified.");
return 1;}
257 else if (strcmp(
"frequency", val) == 0)
259 if (!(val =
Config.GetWord()))
260 {m_log.Emsg(
"Config",
"Loadshed frequency not specified.");
return 1;}
261 if (
XrdOuca2x::a2sz(m_log,
"Loadshed frequency",val,&freq,1,100))
return 1;
265 m_log.Emsg(
"Config",
"Warning - unknown loadshed option specified", val,
".");
269 if (hostname.empty())
271 m_log.Emsg(
"Config",
"must specify hostname for loadshed parameter.");
275 m_loadshed_freq = freq;
276 m_loadshed_hostname = hostname;
277 m_loadshed_port = port;
296int Configuration::xtrace(XrdOucStream &Config)
299 static const struct traceopts {
const char *opname;
int opval;} tropts[] =
311 int i, neg, trval = 0, numopts =
sizeof(tropts)/
sizeof(
struct traceopts);
313 if (!(val =
Config.GetWord()))
315 m_log.Emsg(
"Config",
"trace option not specified");
320 if (!strcmp(val,
"off"))
326 if ((neg = (val[0] ==
'-' && val[1])))
330 for (i = 0; i < numopts; i++)
332 if (!strcmp(val, tropts[i].opname))
336 if (tropts[i].opval) trval &= ~tropts[i].opval;
339 else if (tropts[i].opval) trval |= tropts[i].opval;
346 m_log.Say(
"Config warning: ignoring invalid trace option '", val,
"'.");
351 m_trace_levels = trval;
static int a2sp(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
static int a2sz(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
int Configure(const std::string &config_file)