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 
42 #define MAX_SCHED_PROCS 30000
43 
44 class XrdScheduler : public XrdJob
45 {
46 public:
47 
49 
50 void Cancel(XrdJob *jp);
51 
52 inline int canStick() {return num_Workers < stk_Workers
54 
55 void DoIt();
56 
57 pid_t Fork(const char *id);
58 
59 void *Reaper();
60 
61 void Run();
62 
63 void Schedule(XrdJob *jp);
64 void Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
65 void Schedule(XrdJob *jp, time_t atime);
66 
67 void setParms(int minw, int maxw, int avlt, int maxi, int once=0);
68 
69 void Start();
70 
71 int Stats(char *buff, int blen, int do_sync=0);
72 
73 void TimeSched();
74 
75 // Statistical information
76 //
77 int num_TCreate; // Number of threads created
78 int num_TDestroy;// Number of threads destroyed
79 int num_Jobs; // Number of jobs scheduled
80 int max_QLength; // Longest queue length we had
81 int num_Limited; // Number of times max was reached
82 
83 // Constructor and destructor
84 //
86  int minw=8, int maxw=8192, int maxi=780);
87 
88  ~XrdScheduler();
89 
90 private:
93 
94 XrdSysMutex DispatchMutex; // Disp: Protects above area
95 int idl_Workers; // Disp: Number of idle workers
96 
97 int min_Workers; // Sched: Min threads we need to have
98 int max_Workers; // Sched: Max threads we can start
99 int max_Workidl; // Sched: Max idle time for threads above min_Workers
100 int num_Workers; // Sched: Number of threads we have
101 int stk_Workers; // Sched: Number of sticky workers we can have
102 int num_JobsinQ; // Sched: Number of outstanding jobs in the queue
103 int num_Layoffs; // Sched: Number of threads to terminate
104 
105 XrdJob *WorkFirst; // Pending work
108 XrdSysMutex SchedMutex; // Protects private area
109 
110 XrdJob *TimerQueue; // Pending work
112 XrdSysMutex TimerMutex; // Protects scheduler area
113 
114 XrdSchedulerPID *firstPID;
116 
117 void hireWorker(int dotrace=1);
118 void Monitor();
119 void traceExit(pid_t pid, int status);
120 static const char *TraceID;
121 };
122 #endif
XrdScheduler::~XrdScheduler
~XrdScheduler()
XrdScheduler::num_Jobs
int num_Jobs
Definition: XrdScheduler.hh:79
XrdScheduler::Start
void Start()
XrdScheduler::DispatchMutex
XrdSysMutex DispatchMutex
Definition: XrdScheduler.hh:94
XrdSysMutex
Definition: XrdSysPthread.hh:165
XrdScheduler::max_Workers
int max_Workers
Definition: XrdScheduler.hh:98
XrdSysPthread.hh
XrdScheduler::Cancel
void Cancel(XrdJob *jp)
XrdScheduler::XrdLog
XrdSysError * XrdLog
Definition: XrdScheduler.hh:91
XrdScheduler::XrdTrace
XrdOucTrace * XrdTrace
Definition: XrdScheduler.hh:92
XrdScheduler::Reaper
void * Reaper()
XrdScheduler::num_Layoffs
int num_Layoffs
Definition: XrdScheduler.hh:103
XrdScheduler::WorkLast
XrdJob * WorkLast
Definition: XrdScheduler.hh:106
XrdScheduler::hireWorker
void hireWorker(int dotrace=1)
XrdScheduler::TimerQueue
XrdJob * TimerQueue
Definition: XrdScheduler.hh:110
XrdScheduler::TraceID
static const char * TraceID
Definition: XrdScheduler.hh:120
XrdScheduler::canStick
int canStick()
Definition: XrdScheduler.hh:52
XrdSysCondVar
Definition: XrdSysPthread.hh:78
XrdScheduler::Fork
pid_t Fork(const char *id)
XrdScheduler::firstPID
XrdSchedulerPID * firstPID
Definition: XrdScheduler.hh:114
XrdScheduler::num_Workers
int num_Workers
Definition: XrdScheduler.hh:100
XrdSysSemaphore
Definition: XrdSysPthread.hh:403
XrdScheduler::SchedMutex
XrdSysMutex SchedMutex
Definition: XrdScheduler.hh:108
XrdScheduler::Schedule
void Schedule(XrdJob *jp)
XrdScheduler::Stats
int Stats(char *buff, int blen, int do_sync=0)
XrdScheduler::XrdScheduler
XrdScheduler(XrdSysError *eP, XrdOucTrace *tP, int minw=8, int maxw=8192, int maxi=780)
XrdScheduler
Definition: XrdScheduler.hh:44
XrdScheduler::WorkAvail
XrdSysSemaphore WorkAvail
Definition: XrdScheduler.hh:107
XrdJob
Definition: XrdJob.hh:42
XrdScheduler::num_TCreate
int num_TCreate
Definition: XrdScheduler.hh:77
XrdScheduler::WorkFirst
XrdJob * WorkFirst
Definition: XrdScheduler.hh:105
XrdScheduler::num_JobsinQ
int num_JobsinQ
Definition: XrdScheduler.hh:102
XrdScheduler::TimeSched
void TimeSched()
XrdScheduler::traceExit
void traceExit(pid_t pid, int status)
XrdScheduler::DoIt
void DoIt()
XrdScheduler::Monitor
void Monitor()
XrdScheduler::stk_Workers
int stk_Workers
Definition: XrdScheduler.hh:101
XrdScheduler::setParms
void setParms(int minw, int maxw, int avlt, int maxi, int once=0)
XrdScheduler::Active
int Active()
Definition: XrdScheduler.hh:48
XrdScheduler::num_TDestroy
int num_TDestroy
Definition: XrdScheduler.hh:78
XrdScheduler::TimerRings
XrdSysCondVar TimerRings
Definition: XrdScheduler.hh:111
XrdScheduler::min_Workers
int min_Workers
Definition: XrdScheduler.hh:97
XrdOucTrace
Definition: XrdOucTrace.hh:35
XrdJob.hh
XrdSysError
Definition: XrdSysError.hh:89
XrdScheduler::idl_Workers
int idl_Workers
Definition: XrdScheduler.hh:95
XrdScheduler::Run
void Run()
XrdScheduler::max_QLength
int max_QLength
Definition: XrdScheduler.hh:80
XrdScheduler::TimerMutex
XrdSysMutex TimerMutex
Definition: XrdScheduler.hh:112
XrdScheduler::ReaperMutex
XrdSysMutex ReaperMutex
Definition: XrdScheduler.hh:115
XrdScheduler::max_Workidl
int max_Workidl
Definition: XrdScheduler.hh:99
XrdScheduler::num_Limited
int num_Limited
Definition: XrdScheduler.hh:81