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;
175Configuration::xthrottle(XrdOucStream &Config)
177 long long drate = -1, irate = -1, rint = 1000, climit = -1;
180 while ((val =
Config.GetWord()))
182 if (strcmp(
"data", val) == 0)
184 if (!(val =
Config.GetWord()))
185 {m_log.Emsg(
"Config",
"data throttle limit not specified.");
return 1;}
186 if (
XrdOuca2x::a2sz(m_log,
"data throttle value",val,&drate,1))
return 1;
188 else if (strcmp(
"iops", val) == 0)
190 if (!(val =
Config.GetWord()))
191 {m_log.Emsg(
"Config",
"IOPS throttle limit not specified.");
return 1;}
192 if (
XrdOuca2x::a2sz(m_log,
"IOPS throttle value",val,&irate,1))
return 1;
194 else if (strcmp(
"rint", val) == 0)
196 if (!(val =
Config.GetWord()))
197 {m_log.Emsg(
"Config",
"recompute interval not specified (in ms).");
return 1;}
198 if (
XrdOuca2x::a2sp(m_log,
"recompute interval value (in ms)",val,&rint,10))
return 1;
200 else if (strcmp(
"concurrency", val) == 0)
202 if (!(val =
Config.GetWord()))
203 {m_log.Emsg(
"Config",
"Concurrency limit not specified.");
return 1;}
204 if (
XrdOuca2x::a2sz(m_log,
"Concurrency limit value",val,&climit,1))
return 1;
208 m_log.Emsg(
"Config",
"Warning - unknown throttle option specified", val,
".");
212 m_throttle_data_rate = drate;
213 m_throttle_iops_rate = irate;
214 m_throttle_concurrency_limit = climit;
215 m_throttle_recompute_interval_ms = rint;
235int Configuration::xloadshed(XrdOucStream &Config)
237 long long port = 0, freq = 0;
239 std::string hostname;
241 while ((val =
Config.GetWord()))
243 if (strcmp(
"host", val) == 0)
245 if (!(val =
Config.GetWord()))
246 {m_log.Emsg(
"Config",
"loadshed hostname not specified.");
return 1;}
249 else if (strcmp(
"port", val) == 0)
251 if (!(val =
Config.GetWord()))
252 {m_log.Emsg(
"Config",
"Port number not specified.");
return 1;}
255 else if (strcmp(
"frequency", val) == 0)
257 if (!(val =
Config.GetWord()))
258 {m_log.Emsg(
"Config",
"Loadshed frequency not specified.");
return 1;}
259 if (
XrdOuca2x::a2sz(m_log,
"Loadshed frequency",val,&freq,1,100))
return 1;
263 m_log.Emsg(
"Config",
"Warning - unknown loadshed option specified", val,
".");
267 if (hostname.empty())
269 m_log.Emsg(
"Config",
"must specify hostname for loadshed parameter.");
273 m_loadshed_freq = freq;
274 m_loadshed_hostname = hostname;
275 m_loadshed_port = port;
294int Configuration::xtrace(XrdOucStream &Config)
297 static const struct traceopts {
const char *opname;
int opval;} tropts[] =
309 int i, neg, trval = 0, numopts =
sizeof(tropts)/
sizeof(
struct traceopts);
311 if (!(val =
Config.GetWord()))
313 m_log.Emsg(
"Config",
"trace option not specified");
318 if (!strcmp(val,
"off"))
324 if ((neg = (val[0] ==
'-' && val[1])))
328 for (i = 0; i < numopts; i++)
330 if (!strcmp(val, tropts[i].opname))
334 if (tropts[i].opval) trval &= ~tropts[i].opval;
337 else if (tropts[i].opval) trval |= tropts[i].opval;
344 m_log.Say(
"Config warning: ignoring invalid trace option '", val,
"'.");
349 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)