xrootd
|
00001 #ifndef ___XRD_SCHED_H___ 00002 #define ___XRD_SCHED_H___ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S c h e d u l e r . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 00014 00015 #include <unistd.h> 00016 #include <sys/types.h> 00017 00018 #include "XrdSys/XrdSysPthread.hh" 00019 #include "Xrd/XrdJob.hh" 00020 00021 class XrdSchedulerPID; 00022 00023 class XrdScheduler : public XrdJob 00024 { 00025 public: 00026 00027 int Active() {return num_Workers - idl_Workers + num_JobsinQ;} 00028 00029 void Cancel(XrdJob *jp); 00030 00031 inline int canStick() {return num_Workers < stk_Workers 00032 || (num_Workers-idl_Workers) < stk_Workers;} 00033 00034 void DoIt(); 00035 00036 pid_t Fork(const char *id); 00037 00038 void *Reaper(); 00039 00040 void Run(); 00041 00042 void Schedule(XrdJob *jp); 00043 void Schedule(int num, XrdJob *jfirst, XrdJob *jlast); 00044 void Schedule(XrdJob *jp, time_t atime); 00045 00046 void setParms(int minw, int maxw, int avlt, int maxi, int once=0); 00047 00048 void Start(); 00049 00050 int Stats(char *buff, int blen, int do_sync=0); 00051 00052 void TimeSched(); 00053 00054 // Statistical information 00055 // 00056 int num_TCreate; // Number of threads created 00057 int num_TDestroy;// Number of threads destroyed 00058 int num_Jobs; // Number of jobs scheduled 00059 int max_QLength; // Longest queue length we had 00060 int num_Limited; // Number of times max was reached 00061 00062 // Constructor and destructor 00063 // 00064 XrdScheduler(int minw=8, int maxw=2048, int maxi=780); 00065 00066 ~XrdScheduler(); 00067 00068 private: 00069 XrdSysMutex DispatchMutex; // Disp: Protects above area 00070 int idl_Workers; // Disp: Number of idle workers 00071 00072 int min_Workers; // Sched: Min threads we need to have 00073 int max_Workers; // Sched: Max threads we can start 00074 int max_Workidl; // Sched: Max idle time for threads above min_Workers 00075 int num_Workers; // Sched: Number of threads we have 00076 int stk_Workers; // Sched: Number of sticky workers we can have 00077 int num_JobsinQ; // Sched: Number of outstanding jobs in the queue 00078 int num_Layoffs; // Sched: Number of threads to terminate 00079 00080 XrdJob *WorkFirst; // Pending work 00081 XrdJob *WorkLast; 00082 XrdSysSemaphore WorkAvail; 00083 XrdSysMutex SchedMutex; // Protects private area 00084 00085 XrdJob *TimerQueue; // Pending work 00086 XrdSysCondVar TimerRings; 00087 XrdSysMutex TimerMutex; // Protects scheduler area 00088 00089 XrdSchedulerPID *firstPID; 00090 XrdSysMutex ReaperMutex; 00091 00092 void hireWorker(int dotrace=1); 00093 void Monitor(); 00094 void traceExit(pid_t pid, int status); 00095 static const char *TraceID; 00096 }; 00097 #endif