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 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <unistd.h>
14 #include <sys/types.h>
15 
16 #include "XrdSys/XrdSysPthread.hh"
17 #include "Xrd/XrdJob.hh"
18 
19 class XrdOucTrace;
20 class XrdSchedulerPID;
21 class XrdSysError;
22 
23 class XrdScheduler : public XrdJob
24 {
25 public:
26 
28 
29 void Cancel(XrdJob *jp);
30 
31 inline int canStick() {return num_Workers < stk_Workers
33 
34 void DoIt();
35 
36 pid_t Fork(const char *id);
37 
38 void *Reaper();
39 
40 void Run();
41 
42 void Schedule(XrdJob *jp);
43 void Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
44 void Schedule(XrdJob *jp, time_t atime);
45 
46 void setParms(int minw, int maxw, int avlt, int maxi, int once=0);
47 
48 void Start();
49 
50 int Stats(char *buff, int blen, int do_sync=0);
51 
52 void TimeSched();
53 
54 // Statistical information
55 //
56 int num_TCreate; // Number of threads created
57 int num_TDestroy;// Number of threads destroyed
58 int num_Jobs; // Number of jobs scheduled
59 int max_QLength; // Longest queue length we had
60 int num_Limited; // Number of times max was reached
61 
62 // Constructor and destructor
63 //
65  int minw=8, int maxw=2048, int maxi=780);
66 
67  ~XrdScheduler();
68 
69 private:
72 
73 XrdSysMutex DispatchMutex; // Disp: Protects above area
74 int idl_Workers; // Disp: Number of idle workers
75 
76 int min_Workers; // Sched: Min threads we need to have
77 int max_Workers; // Sched: Max threads we can start
78 int max_Workidl; // Sched: Max idle time for threads above min_Workers
79 int num_Workers; // Sched: Number of threads we have
80 int stk_Workers; // Sched: Number of sticky workers we can have
81 int num_JobsinQ; // Sched: Number of outstanding jobs in the queue
82 int num_Layoffs; // Sched: Number of threads to terminate
83 
84 XrdJob *WorkFirst; // Pending work
87 XrdSysMutex SchedMutex; // Protects private area
88 
89 XrdJob *TimerQueue; // Pending work
91 XrdSysMutex TimerMutex; // Protects scheduler area
92 
95 
96 void hireWorker(int dotrace=1);
97 void Monitor();
98 void traceExit(pid_t pid, int status);
99 static const char *TraceID;
100 };
101 #endif