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 class XrdScheduler : public XrdJob
00043 {
00044 public:
00045 
00046 int           Active() {return num_Workers - idl_Workers + num_JobsinQ;}
00047 
00048 void          Cancel(XrdJob *jp);
00049 
00050 inline int    canStick() {return  num_Workers              < stk_Workers
00051                               || (num_Workers-idl_Workers) < stk_Workers;}
00052 
00053 void          DoIt();
00054 
00055 pid_t         Fork(const char *id);
00056 
00057 void         *Reaper();
00058 
00059 void          Run();
00060 
00061 void          Schedule(XrdJob *jp);
00062 void          Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
00063 void          Schedule(XrdJob *jp, time_t atime);
00064 
00065 void          setParms(int minw, int maxw, int avlt, int maxi, int once=0);
00066 
00067 void          Start();
00068 
00069 int           Stats(char *buff, int blen, int do_sync=0);
00070 
00071 void          TimeSched();
00072 
00073 // Statistical information
00074 //
00075 int        num_TCreate; // Number of threads created
00076 int        num_TDestroy;// Number of threads destroyed
00077 int        num_Jobs;    // Number of jobs scheduled
00078 int        max_QLength; // Longest queue length we had
00079 int        num_Limited; // Number of times max was reached
00080 
00081 // Constructor and destructor
00082 //
00083               XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
00084                            int minw=8, int maxw=8192, int maxi=780);
00085 
00086              ~XrdScheduler();
00087 
00088 private:
00089 XrdSysError *XrdLog;
00090 XrdOucTrace *XrdTrace;
00091 
00092 XrdSysMutex DispatchMutex; // Disp: Protects above area
00093 int        idl_Workers;    // Disp: Number of idle workers
00094 
00095 int        min_Workers;   // Sched: Min threads we need to have
00096 int        max_Workers;   // Sched: Max threads we can start
00097 int        max_Workidl;   // Sched: Max idle time for threads above min_Workers
00098 int        num_Workers;   // Sched: Number of threads we have
00099 int        stk_Workers;   // Sched: Number of sticky workers we can have
00100 int        num_JobsinQ;   // Sched: Number of outstanding jobs in the queue
00101 int        num_Layoffs;   // Sched: Number of threads to terminate
00102 
00103 XrdJob                *WorkFirst;  // Pending work
00104 XrdJob                *WorkLast;
00105 XrdSysSemaphore        WorkAvail;
00106 XrdSysMutex            SchedMutex; // Protects private area
00107 
00108 XrdJob                *TimerQueue; // Pending work
00109 XrdSysCondVar          TimerRings;
00110 XrdSysMutex            TimerMutex; // Protects scheduler area
00111 
00112 XrdSchedulerPID       *firstPID;
00113 XrdSysMutex            ReaperMutex;
00114 
00115 void hireWorker(int dotrace=1);
00116 void Monitor();
00117 void traceExit(pid_t pid, int status);
00118 static const char *TraceID;
00119 };
00120 #endif

Generated on 12 Dec 2014 for xrootd by  doxygen 1.4.7