#include "dnxWLM.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxLogging.h"
#include "dnxTransport.h"
#include "dnxSleep.h"
#include "dnxClntProt.h"
#include "dnxPlugin.h"
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <ifaddrs.h>
Go to the source code of this file.
Data Structures | |
struct | DnxWorkerStatus |
A structure that describes the attribues of a pool thread. More... | |
struct | iDnxWlm |
The implementation of a work load manager object. More... | |
Defines | |
#define | elemcount(x) (sizeof(x)/sizeof(*(x))) |
#define | MAX_RESULT_DATA 1024 |
#define | MAX_IP_ADDRSZ 64 |
Enumerations | |
enum | DnxThreadState { DNX_THREAD_DEAD = 0, DNX_THREAD_RUNNING, DNX_THREAD_ZOMBIE } |
A value that indicates that current state of a pool thread. More... | |
Functions | |
static void * | dnxWorker (void *data) |
The main thread routine for a worker thread. | |
static void | logConfigChanges (DnxWlmCfgData *ocp, DnxWlmCfgData *ncp) |
Log changes between old and new configuration data sets. | |
static int | initWorkerComm (DnxWorkerStatus *ws) |
Initialize worker thread communication resources. | |
static void | releaseWorkerComm (DnxWorkerStatus *ws) |
Clean up worker thread communications resources. | |
static int | workerCreate (iDnxWlm *iwlm, DnxWorkerStatus **pws) |
Create a new worker thread. | |
static void | cleanThreadPool (iDnxWlm *iwlm) |
Clean up zombie threads and compact the thread pool. | |
static int | growThreadPool (iDnxWlm *iwlm) |
Grow the thread pool to the configured number of threads. | |
static void | dnxWorkerCleanup (void *data) |
Dispatch thread clean-up routine. | |
void | dnxWlmResetStats (DnxWlm *wlm) |
Reset all WLM statistics counters. | |
void | dnxWlmGetStats (DnxWlm *wlm, DnxWlmStats *wsp) |
Return a snapshot of WLM statistics. | |
int | dnxWlmReconfigure (DnxWlm *wlm, DnxWlmCfgData *cfg) |
Reconfigure an existing Work Load Manager object. | |
int | dnxWlmCreate (DnxWlmCfgData *cfg, DnxWlm **pwlm) |
Creates a new Work Load Manager object. | |
void | dnxWlmDestroy (DnxWlm *wlm) |
The main thread routine for the work load manager. |
Functions:
1. Started by the DNX Client main 2. Creates the initial thread pool 3. Monitors the thread pool for the need to increase worker thread count 4. Cleans-up worker threads upon shutdown
Definition in file dnxWLM.c.
#define MAX_RESULT_DATA 1024 |
Definition at line 64 of file dnxWLM.c.
Referenced by dnxWorker().
enum DnxThreadState |
static void cleanThreadPool | ( | iDnxWlm * | iwlm | ) | [static] |
Clean up zombie threads and compact the thread pool.
[in] | iwlm | - a pointer to the work load manager data structure. |
Definition at line 308 of file dnxWLM.c.
References DNX_THREAD_ZOMBIE, dnxDebug(), iDnxWlm::pool, releaseWorkerComm(), DnxWorkerStatus::state, iDnxWlm::tdestroyed, iDnxWlm::threads, iDnxWlm::threadtm, DnxWorkerStatus::tid, DnxWorkerStatus::tstart, and xfree.
Referenced by dnxWlmDestroy(), and dnxWorker().
int dnxWlmCreate | ( | DnxWlmCfgData * | cfg, | |
DnxWlm ** | pwlm | |||
) |
Creates a new Work Load Manager object.
[in] | cfg | - a reference to the WLM configuration data structure. |
[out] | pwlm | - the address of storage for the returned WLM object. |
Definition at line 676 of file dnxWLM.c.
References iDnxWlm::cfg, DnxWlmCfgData::collectorUrl, DnxWlmCfgData::dispatcherUrl, DNX_ERR_MEMORY, DNX_OK, DNX_PT_MUTEX_DESTROY, DNX_PT_MUTEX_INIT, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, dnxErrorString(), dnxLog(), growThreadPool(), iDnxWlm::minexectm, iDnxWlm::mutex, iDnxWlm::myipaddr, iDnxWlm::myipaddrstr, iDnxWlm::pool, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, iDnxWlm::poolsz, iDnxWlm::threads, xfree, xmalloc, and xstrdup.
Referenced by main().
void dnxWlmDestroy | ( | DnxWlm * | wlm | ) |
The main thread routine for the work load manager.
[in] | wlm | - the work load manager object to be destroyed. |
Definition at line 769 of file dnxWLM.c.
References iDnxWlm::cfg, cleanThreadPool(), DnxWlmCfgData::collectorUrl, DnxWlmCfgData::dispatcherUrl, DNX_PT_MUTEX_DESTROY, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, DNX_THREAD_RUNNING, dnxCancelableSleep(), dnxDebug(), dnxLog(), iDnxWlm::mutex, iDnxWlm::pool, DnxWlmCfgData::shutdownGrace, DnxWorkerStatus::state, iDnxWlm::terminate, iDnxWlm::threads, DnxWorkerStatus::tid, and xfree.
Referenced by main().
void dnxWlmGetStats | ( | DnxWlm * | wlm, | |
DnxWlmStats * | wsp | |||
) |
Return a snapshot of WLM statistics.
[in] | wlm | - the Work Load Manager whose stats are to be returned. |
[out] | wsp | - the address of storage for the WLM stats to be returned. |
Definition at line 591 of file dnxWLM.c.
References iDnxWlm::active, DnxWlmStats::active_threads, DnxWlmStats::avg_active_threads, DnxWlmStats::avg_exec_time, DnxWlmStats::avg_total_threads, iDnxWlm::avgactive, iDnxWlm::avgexectm, iDnxWlm::avgthreads, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, DnxWlmStats::job_time, DnxWlmStats::jobs_failed, DnxWlmStats::jobs_received, DnxWlmStats::jobs_succeeded, iDnxWlm::jobsfail, iDnxWlm::jobsok, iDnxWlm::jobsrcvd, iDnxWlm::jobtm, DnxWlmStats::max_exec_time, iDnxWlm::maxexectm, DnxWlmStats::min_exec_time, iDnxWlm::minexectm, iDnxWlm::mutex, iDnxWlm::packets_in, DnxWlmStats::packets_in, iDnxWlm::packets_out, DnxWlmStats::packets_out, iDnxWlm::reqsent, DnxWlmStats::requests_sent, iDnxWlm::tcreated, iDnxWlm::tdestroyed, DnxWlmStats::thread_time, iDnxWlm::threads, DnxWlmStats::threads_created, DnxWlmStats::threads_destroyed, iDnxWlm::threadtm, and DnxWlmStats::total_threads.
Referenced by buildMgmtStatsReply().
int dnxWlmReconfigure | ( | DnxWlm * | wlm, | |
DnxWlmCfgData * | cfg | |||
) |
Reconfigure an existing Work Load Manager object.
[in] | wlm | - the work load manager object to be reconfigured. |
[in] | cfg | - the new configuration parameters. |
Definition at line 620 of file dnxWLM.c.
References iDnxWlm::cfg, DNX_ERR_MEMORY, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, dnxCancelableSleep(), logConfigChanges(), DnxWlmCfgData::maxResults, DnxWlmCfgData::maxRetries, iDnxWlm::mutex, DnxWlmCfgData::pollInterval, iDnxWlm::pool, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, iDnxWlm::poolsz, DnxWlmCfgData::reqTimeout, DnxWlmCfgData::showNodeAddr, DnxWlmCfgData::shutdownGrace, iDnxWlm::threads, DnxWlmCfgData::ttlBackoff, and xrealloc.
void dnxWlmResetStats | ( | DnxWlm * | wlm | ) |
Reset all WLM statistics counters.
[in] | wlm | - the Work Load Manager whose stats counters are to be reset. |
Definition at line 572 of file dnxWLM.c.
References iDnxWlm::avgactive, iDnxWlm::avgexectm, iDnxWlm::avgthreads, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, iDnxWlm::jobsfail, iDnxWlm::jobsok, iDnxWlm::jobsrcvd, iDnxWlm::jobtm, iDnxWlm::maxexectm, iDnxWlm::minexectm, iDnxWlm::mutex, iDnxWlm::packets_in, iDnxWlm::packets_out, iDnxWlm::reqsent, iDnxWlm::tcreated, iDnxWlm::tdestroyed, and iDnxWlm::threadtm.
Referenced by processCommands().
static void * dnxWorker | ( | void * | data | ) | [static] |
The main thread routine for a worker thread.
[in] | data | - an opaque pointer to a DnxWorkerStatus structure for this thread. |
Definition at line 403 of file dnxWLM.c.
References iDnxWlm::active, iDnxWlm::avgexectm, iDnxWlm::cfg, cleanThreadPool(), DnxJob::cmd, DnxWorkerStatus::collect, DnxResult::delta, DnxWorkerStatus::dispatch, DNX_ERR_ADDRESS, DNX_ERR_TIMEOUT, DNX_JOB_COMPLETE, DNX_OBJ_WORKER, DNX_OK, DNX_PLUGIN_RESULT_OK, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, DNX_REQ_REGISTER, dnxCancelableSleep(), dnxDebug(), dnxErrorString(), dnxLog(), dnxMakeXID(), dnxPluginExecute(), dnxSendNodeRequest(), dnxSendResult(), dnxWaitForJob(), dnxWorkerCleanup(), growThreadPool(), DnxWorkerStatus::iwlm, DnxNodeRequest::jobCap, iDnxWlm::jobsfail, iDnxWlm::jobsok, iDnxWlm::jobsrcvd, iDnxWlm::jobtm, MAX_RESULT_DATA, iDnxWlm::maxexectm, DnxWlmCfgData::maxRetries, iDnxWlm::minexectm, iDnxWlm::mutex, iDnxWlm::myipaddr, iDnxWlm::myipaddrstr, DnxXID::objSerial, DnxXID::objSlot, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, iDnxWlm::reqsent, DnxWlmCfgData::reqTimeout, DnxNodeRequest::reqType, DnxResult::resCode, DnxResult::resData, DnxWorkerStatus::serial, DnxWlmCfgData::showNodeAddr, DnxResult::state, iDnxWlm::terminate, iDnxWlm::threads, DnxJob::timeout, DnxWorkerStatus::tstart, DnxNodeRequest::ttl, DnxWlmCfgData::ttlBackoff, xfree, DnxResult::xid, DnxJob::xid, DnxNodeRequest::xid, and xstrdup.
Referenced by workerCreate().
static void dnxWorkerCleanup | ( | void * | data | ) | [static] |
Dispatch thread clean-up routine.
[in] | data | - an opaque pointer to a worker's status data structure. |
Definition at line 386 of file dnxWLM.c.
References DNX_THREAD_ZOMBIE, dnxDebug(), and DnxWorkerStatus::state.
Referenced by dnxWorker().
static int growThreadPool | ( | iDnxWlm * | iwlm | ) | [static] |
Grow the thread pool to the configured number of threads.
This routine calculates an appropriate growth factor. If the current number of threads is less than the requested initial pool size, then the pool is grown to the initial pool size. If the current number of threads is near the maximum pool size, then only grow to the maximum. Otherwise it is grown by the configured pool growth value.
[in] | iwlm | - a reference to the work load manager whose thread pool size is to be increased. |
Definition at line 355 of file dnxWLM.c.
References iDnxWlm::cfg, dnxLog(), iDnxWlm::pool, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, iDnxWlm::tcreated, iDnxWlm::threads, and workerCreate().
Referenced by dnxWlmCreate(), and dnxWorker().
static int initWorkerComm | ( | DnxWorkerStatus * | ws | ) | [static] |
Initialize worker thread communication resources.
[in] | ws | - a pointer to a worker thread's status data structure. |
Definition at line 200 of file dnxWLM.c.
References iDnxWlm::cfg, DnxWorkerStatus::collect, DnxWlmCfgData::collectorUrl, DnxWorkerStatus::dispatch, DnxWlmCfgData::dispatcherUrl, DNX_MODE_ACTIVE, DNX_OK, dnxChanMapAdd(), dnxChanMapDelete(), dnxConnect(), dnxDisconnect(), dnxErrorString(), dnxLog(), elemcount, and DnxWorkerStatus::iwlm.
Referenced by workerCreate().
static void logConfigChanges | ( | DnxWlmCfgData * | ocp, | |
DnxWlmCfgData * | ncp | |||
) | [static] |
Log changes between old and new configuration data sets.
Dynamic reconfiguration of dispatcher and collector URL's is not allowed so we don't need to check differences in those string values.
[in] | ocp | - a reference to the old configuration data set. |
[in] | ncp | - a reference to the new configuration data set. |
Definition at line 134 of file dnxWLM.c.
References DnxWlmCfgData::collectorUrl, DnxWlmCfgData::dispatcherUrl, dnxLog(), DnxWlmCfgData::maxResults, DnxWlmCfgData::maxRetries, DnxWlmCfgData::pollInterval, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, DnxWlmCfgData::reqTimeout, DnxWlmCfgData::showNodeAddr, DnxWlmCfgData::shutdownGrace, and DnxWlmCfgData::ttlBackoff.
Referenced by dnxWlmReconfigure().
static void releaseWorkerComm | ( | DnxWorkerStatus * | ws | ) | [static] |
Clean up worker thread communications resources.
[in] | ws | - a pointer to a worker thread's status data structure. |
Definition at line 246 of file dnxWLM.c.
References DnxWorkerStatus::collect, DnxWorkerStatus::dispatch, dnxChanMapDelete(), and dnxDisconnect().
Referenced by cleanThreadPool(), and workerCreate().
static int workerCreate | ( | iDnxWlm * | iwlm, | |
DnxWorkerStatus ** | pws | |||
) | [static] |
Create a new worker thread.
[in] | iwlm | - the WLM object whose thread pool is being updated. |
[in] | pws | - the address of storage for the address of the newly allocated and configured worker status structure. |
Definition at line 271 of file dnxWLM.c.
References DNX_ERR_MEMORY, DNX_ERR_THREAD, DNX_THREAD_RUNNING, dnxErrorString(), dnxLog(), dnxWorker(), initWorkerComm(), DnxWorkerStatus::iwlm, releaseWorkerComm(), DnxWorkerStatus::state, DnxWorkerStatus::tid, xfree, and xmalloc.
Referenced by growThreadPool().