XrdScheduler.hh

Go to the documentation of this file.
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 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00010 /*                                                                            */
00011 /* This file is part of the XRootD software suite.                            */
00012 /*                                                                            */
00013 /* XRootD is free software: you can redistribute it and/or modify it under    */
00014 /* the terms of the GNU Lesser General Public License as published by the     */
00015 /* Free Software Foundation, either version 3 of the License, or (at your     */
00016 /* option) any later version.                                                 */
00017 /*                                                                            */
00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00021 /* License for more details.                                                  */
00022 /*                                                                            */
00023 /* You should have received a copy of the GNU Lesser General Public License   */
00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00026 /*                                                                            */
00027 /* The copyright holder's institutional names and contributor's names may not */
00028 /* be used to endorse or promote products derived from this software without  */
00029 /* specific prior written permission of the institution or contributor.       */
00030 /******************************************************************************/
00031 
00032 #include <unistd.h>
00033 #include <sys/types.h>
00034 
00035 #include "XrdSys/XrdSysPthread.hh"
00036 #include "Xrd/XrdJob.hh"
00037 
00038 class XrdOucTrace;
00039 class XrdSchedulerPID;
00040 class XrdSysError;
00041 
00042 #define MAX_SCHED_PROCS 30000
00043 
00044 class XrdScheduler : public XrdJob
00045 {
00046 public:
00047 
00048 int           Active() {return num_Workers - idl_Workers + num_JobsinQ;}
00049 
00050 void          Cancel(XrdJob *jp);
00051 
00052 inline int    canStick() {return  num_Workers              < stk_Workers
00053                               || (num_Workers-idl_Workers) < stk_Workers;}
00054 
00055 void          DoIt();
00056 
00057 pid_t         Fork(const char *id);
00058 
00059 void         *Reaper();
00060 
00061 void          Run();
00062 
00063 void          Schedule(XrdJob *jp);
00064 void          Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
00065 void          Schedule(XrdJob *jp, time_t atime);
00066 
00067 void          setParms(int minw, int maxw, int avlt, int maxi, int once=0);
00068 
00069 void          Start();
00070 
00071 int           Stats(char *buff, int blen, int do_sync=0);
00072 
00073 void          TimeSched();
00074 
00075 // Statistical information
00076 //
00077 int        num_TCreate; // Number of threads created
00078 int        num_TDestroy;// Number of threads destroyed
00079 int        num_Jobs;    // Number of jobs scheduled
00080 int        max_QLength; // Longest queue length we had
00081 int        num_Limited; // Number of times max was reached
00082 
00083 // Constructor and destructor
00084 //
00085               XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
00086                            int minw=8, int maxw=8192, int maxi=780);
00087 
00088              ~XrdScheduler();
00089 
00090 private:
00091 XrdSysError *XrdLog;
00092 XrdOucTrace *XrdTrace;
00093 
00094 XrdSysMutex DispatchMutex; // Disp: Protects above area
00095 int        idl_Workers;    // Disp: Number of idle workers
00096 
00097 int        min_Workers;   // Sched: Min threads we need to have
00098 int        max_Workers;   // Sched: Max threads we can start
00099 int        max_Workidl;   // Sched: Max idle time for threads above min_Workers
00100 int        num_Workers;   // Sched: Number of threads we have
00101 int        stk_Workers;   // Sched: Number of sticky workers we can have
00102 int        num_JobsinQ;   // Sched: Number of outstanding jobs in the queue
00103 int        num_Layoffs;   // Sched: Number of threads to terminate
00104 
00105 XrdJob                *WorkFirst;  // Pending work
00106 XrdJob                *WorkLast;
00107 XrdSysSemaphore        WorkAvail;
00108 XrdSysMutex            SchedMutex; // Protects private area
00109 
00110 XrdJob                *TimerQueue; // Pending work
00111 XrdSysCondVar          TimerRings;
00112 XrdSysMutex            TimerMutex; // Protects scheduler area
00113 
00114 XrdSchedulerPID       *firstPID;
00115 XrdSysMutex            ReaperMutex;
00116 
00117 void hireWorker(int dotrace=1);
00118 void Monitor();
00119 void traceExit(pid_t pid, int status);
00120 static const char *TraceID;
00121 };
00122 #endif

Generated on 5 Oct 2016 for xrootd by  doxygen 1.4.7