XRootD
XrdScheduler.hh
Go to the documentation of this file.
1 #ifndef ___XRD_SCHED_H___
2 #define ___XRD_SCHED_H___
3 /******************************************************************************/
4 /* */
5 /* X r d S c h e d u l e r . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <unistd.h>
33 #include <sys/types.h>
34 
35 #include "XrdSys/XrdSysPthread.hh"
36 #include "Xrd/XrdJob.hh"
37 
38 class XrdOucTrace;
39 class XrdSchedulerPID;
40 class XrdSysError;
41 class XrdSysTrace;
42 
43 #define MAX_SCHED_PROCS 30000
44 #define DFL_SCHED_PROCS 8192
45 
46 class XrdScheduler : public XrdJob
47 {
48 public:
49 
50 int Active() {return num_Workers - idl_Workers + num_JobsinQ;}
51 
52 void Cancel(XrdJob *jp);
53 
54 inline int canStick() {return num_Workers < stk_Workers
55  || (num_Workers-idl_Workers) < stk_Workers;}
56 
57 void DoIt();
58 
59 pid_t Fork(const char *id);
60 
61 void *Reaper();
62 
63 void Run();
64 
65 void Schedule(XrdJob *jp);
66 void Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
67 void Schedule(XrdJob *jp, time_t atime);
68 
69 void setParms(int minw, int maxw, int avlt, int maxi, int once=0);
70 
71 void Start();
72 
73 int Stats(char *buff, int blen, int do_sync=0);
74 
75 void TimeSched();
76 
77 void setNproc(const bool limlower);
78 
79 // Statistical information
80 //
81 int num_TCreate; // Number of threads created
82 int num_TDestroy;// Number of threads destroyed
83 int num_Jobs; // Number of jobs scheduled
84 int max_QLength; // Longest queue length we had
85 int num_Limited; // Number of times max was reached
86 
87 // This is the preferred constructor
88 //
90  int minw=8, int maxw=8192, int maxi=780);
91 
92 // This constructor is only maintained for ABI compatibility and will be
93 // removed in a future major release. While syntactically compatible the
94 // sematics now are slightly different and tracing might not occur.
95 //
97  int minw=8, int maxw=8192, int maxi=780);
98 
99 // This constructor is used for a stand-alone scheduler.
100 //
101  XrdScheduler(int minw=3, int maxw=128, int maxi=12);
102 
103  ~XrdScheduler();
104 
105 private:
106 XrdSysError *XrdLog;
107 XrdSysTrace *XrdTrace;
108 XrdOucTrace *XrdTraceOld; // This is only used for ABI compatibility
109 
110 XrdSysMutex DispatchMutex; // Disp: Protects above area
111 int idl_Workers; // Disp: Number of idle workers
112 
113 int min_Workers; // Sched: Min threads we need to have
114 int max_Workers; // Sched: Max threads we can start
115 int max_Workidl; // Sched: Max idle time for threads above min_Workers
116 int num_Workers; // Sched: Number of threads we have
117 int stk_Workers; // Sched: Number of sticky workers we can have
118 int num_JobsinQ; // Sched: Number of outstanding jobs in the queue
119 int num_Layoffs; // Sched: Number of threads to terminate
120 
121 XrdJob *WorkFirst; // Pending work
122 XrdJob *WorkLast;
123 XrdSysSemaphore WorkAvail;
124 XrdSysMutex SchedMutex; // Protects private area
125 
126 XrdJob *TimerQueue; // Pending work
127 XrdSysCondVar TimerRings;
128 XrdSysMutex TimerMutex; // Protects scheduler area
129 
130 XrdSchedulerPID *firstPID;
131 XrdSysMutex ReaperMutex;
132 
133 void Boot(XrdSysError *eP, XrdSysTrace *tP, int minw, int maxw, int maxi);
134 void hireWorker(int dotrace=1);
135 void Init(int minw, int maxw, int maxi);
136 void Monitor();
137 void traceExit(pid_t pid, int status);
138 static const char *TraceID;
139 };
140 #endif
Definition: XrdJob.hh:43
friend class XrdScheduler
Definition: XrdJob.hh:44
int Stats(char *buff, int blen, int do_sync=0)
void Schedule(XrdJob *jp)
void TimeSched()
void setParms(int minw, int maxw, int avlt, int maxi, int once=0)
void Cancel(XrdJob *jp)
void * Reaper()
void setNproc(const bool limlower)
pid_t Fork(const char *id)