Search Toolkit Book for CSrvTask
Main working entity in TaskServer. More...
#include "srv_tasks.hpp"
(Private to src/app/netcache
.)
Main working entity in TaskServer.
It's called "task" because it should work like task/process in OS with cooperative multi-tasking. Everything that task want to do should be divided into relatively small pieces – slices. OS (TaskServer in this case) will provide time slices to each task, they should execute a portion of their work during this slice and then return control back to OS to give other tasks a chance to have their time slice of the processor (thread in case of TaskServer). Each slice of work done by the task should be less than jiffy (0.01 second by default), preferably one or two orders of magnitude less than jiffy. This way TaskServer will be able to schedule all tasks more effectively and spread the load evenly between threads.
Definition at line 87 of file srv_tasks.hpp.
◆ CSrvTask() [1/2] CSrvTask::CSrvTask ( void ) ◆ CSrvTask() [2/2] ◆ ~CSrvTask() CSrvTask::~CSrvTask ( void ) virtual ◆ CreateNewDiagCtx() void CSrvTask::CreateNewDiagCtx ( void ) ◆ ExecuteSlice()This is the main method to do all work this task should do.
This method will be called periodically while somebody calls SetRunnable() or RunAfter() on this task. But number of calls to this method won't match number of calls to SetRunnable() – if several calls to SetRunnable() are made before ExecuteSlice() had a chance to execute it will be called only once. Task's code inside ExecuteSlice() should understand itself how much work it needs to do and call SetRunnable() again if needed (or do all the work before returning from ExecuteSlice()). Parameter thr_num is number of thread on which ExecuteSlice() is called.
Implemented in CSrvStatesTask< Derived >, CSrvStatesTask< CBulkCleaner >, CSrvStatesTask< CExpiredCleaner >, CSrvStatesTask< CNCMessageHandler >, CSrvStatesTask< CNCActiveHandler >, CSrvStatesTask< CNCActiveSyncControl >, CSrvStatesTask< CDiskFlusher >, CSrvStatesTask< CSpaceShrinker >, CSrvStatesTask< CBlobCacher >, CSrvListener, CTZAdjuster, CRecNoSaver, CNewFileCreator, CNCPeerControl, CNCHeartBeat, CWriteBackControl, CCurVerReader, CNCBlobAccessor, CNCBlobVerManager, CStatRotator, SNCBlobVerData, CMMFlusher, CLogWriter, CNCActiveHandler_Proxy, and CNCLogCleaner.
Referenced by CSrvSocketTask::InternalRunSlice(), and InternalRunSlice().
◆ GetDiagCtx()Get current diagnostic context for the task.
Definition at line 353 of file srv_inlines.hpp.
References m_DiagCtx.
Referenced by s_CleanSockResources(), s_CreateDiagRequest(), s_DoCleanLog(), CNCActiveHandler::SetProxy(), CNCActiveHandler::SyncBlobsList(), CNCActiveHandler::SyncCancel(), CNCActiveHandler::SyncCommit(), CNCActiveHandler::SyncProlongOur(), CNCActiveHandler::SyncProlongPeer(), CNCActiveHandler::SyncSend(), CNCActiveHandler::SyncStart(), CNCMessageHandler::x_AssignCmdParams(), CBlobCacher::x_CancelCaching(), CNCActiveHandler::x_CleanCmdResources(), CNCMessageHandler::x_CleanCmdResources(), CNCMessageHandler::x_CloseCmdAndConn(), CNCMessageHandler::x_CloseOnPeerError(), CExpiredCleaner::x_DeleteNextData(), CBlobCacher::x_DelFileAndRetryCreate(), CNCMessageHandler::x_DoCmd_CopyProlong(), CNCMessageHandler::x_DoCmd_CopyPut(), CNCMessageHandler::x_DoCmd_Get(), CNCMessageHandler::x_DoCmd_GetStat(), CNCMessageHandler::x_DoCmd_HasBlob(), CNCMessageHandler::x_DoCmd_IC_Store(), CNCMessageHandler::x_DoCmd_Put(), CNCMessageHandler::x_DoCmd_ReConfig(), CNCMessageHandler::x_DoCmd_SetValid(), CNCMessageHandler::x_DoCmd_SyncGet(), CNCMessageHandler::x_DoCmd_SyncStart(), CNCActiveHandler::x_DoSyncGet(), CBulkCleaner::x_Finalize(), CNCMessageHandler::x_FinishCommand(), CSpaceShrinker::x_FinishMoves(), CNCMessageHandler::x_FinishReadingBlob(), CNCActiveSyncControl::x_FinishSync(), CNCActiveHandler::x_ProcessPeerError(), CNCMessageHandler::x_ProxyToNextPeer(), CNCMessageHandler::x_ReadAuthMessage(), CNCMessageHandler::x_ReadBlobChunk(), CNCMessageHandler::x_ReadBlobChunkLength(), CNCMessageHandler::x_ReadBlobSignature(), CNCMessageHandler::x_ReadCommand(), CNCActiveHandler::x_ReadCopyProlong(), CNCActiveHandler::x_ReadDataPrefix(), CNCActiveHandler::x_ReadHttpDataPrefix(), CNCActiveHandler::x_ReplaceServerConn(), CNCMessageHandler::x_ReportError(), CNCMessageHandler::x_SendCmdAsProxy(), CNCActiveHandler::x_SendCopyPutCmd(), CNCMessageHandler::x_SendGetMetaCmd(), CNCMessageHandler::x_SendPurgeToPeerCmd(), CNCMessageHandler::x_SendPutToPeerCmd(), CNCMessageHandler::x_StartCommand(), CNCMessageHandler::x_WaitForPeerAnswer(), CNCMessageHandler::x_WriteBlobData(), CNCMessageHandler::x_WriteHttpResponse(), and CNCActiveHandler::~CNCActiveHandler().
◆ GetPriority() Uint4 CSrvTask::GetPriority ( void ) inline ◆ InternalRunSlice() ◆ operator=() ◆ PrintState() ◆ ReleaseDiagCtx() void CSrvTask::ReleaseDiagCtx ( void )Releases current diagnostic context of the task.
Method must be called for all contexts created via CreateNewDiagCtx() or set via SetDiagCtx(). You cannot make more calls and you must not make less calls than CreateNewDiagCtx() and SetDiagCtx() combined. Both erroneous situations will result in program abort.
Definition at line 1261 of file logging.cpp.
References GetMemSize(), m_DiagChain, m_DiagChainSize, m_DiagCtx, NULL, CObject::RemoveReference(), and SRV_FATAL.
Referenced by s_CleanSockResources(), s_DoCleanLog(), CBlobCacher::x_CancelCaching(), CNCActiveHandler::x_CleanCmdResources(), CNCMessageHandler::x_CleanCmdResources(), CNCActiveHandler::x_CloseConn(), CBlobCacher::x_FinishCaching(), CSpaceShrinker::x_FinishMoves(), CExpiredCleaner::x_FinishSession(), CBulkCleaner::x_FinishSession(), CNCActiveSyncControl::x_FinishSync(), CNCMessageHandler::x_ReadCommand(), CNCActiveHandler::x_ReadCopyProlong(), CNCActiveHandler::x_ReadDataForClient(), CNCActiveHandler::x_ReplaceServerConn(), and CNCActiveHandler::~CNCActiveHandler().
◆ RunAfter() void CSrvTask::RunAfter ( Uint4 delay_sec )This call is basically equivalent to SetRunnable() but with guarantee that task will be scheduled for execution no earlier than delay_sec later (approximately, can be up to a second less if measured in absolute wall time).
If SetRunnable() is called while task is waiting for its delay timer then timer is canceled and task should set this timer inside ExecuteSlice() again if it still needs it. Timers are never set if TaskServer is shutting down (CTaskServer::IsInShutdown() returns TRUE). In this case ExecuteSlice() will be called immediately after call to RunAfter() and task should recognize state of shutting down and behave accordingly. This method is not thread-safe and should be called only from inside ExecuteSlice() method.
Definition at line 216 of file timers.cpp.
References ACCESS_ONCE, AtomicCAS(), Critical(), CSrvTime::CurSecs(), fTaskOnTimer, fTaskQueued, fTaskRunnable, CTaskServer::IsInShutdown(), CMiniMutex::Lock(), m_TaskFlags, m_Timer, RemoveTaskFromTimer(), s_AddTimerTicket(), s_TimerLock, SetRunnable(), SRV_LOG, STimerTicket::task, STimerTicket::timer_time, and CMiniMutex::Unlock().
Referenced by CStatRotator::CalcNextRun(), CNCLogCleaner::ExecuteSlice(), CMMFlusher::ExecuteSlice(), CNCBlobVerManager::ExecuteSlice(), CWriteBackControl::ExecuteSlice(), CNCHeartBeat::ExecuteSlice(), CNCPeerControl::ExecuteSlice(), CRecNoSaver::ExecuteSlice(), CTZAdjuster::ExecuteSlice(), InitMemoryMan(), CDiskFlusher::x_CheckFlushTime(), CBlobCacher::x_DelFileAndRetryCreate(), CNCActiveSyncControl::x_ExecuteFinalize(), CNCActiveSyncControl::x_FinishScanSlots(), CSpaceShrinker::x_FinishSession(), CExpiredCleaner::x_FinishSession(), CNCMessageHandler::x_ReadBlobChunkLength(), CNCActiveSyncControl::x_StartScanSlots(), CBulkCleaner::x_StartSession(), CNCActiveSyncControl::x_WaitForExecutingTasks(), SNCBlobVerData::x_WriteBlobInfo(), and SNCBlobVerData::x_WriteCurChunk().
◆ SetDiagCtx()Set diagnostic context for this task to work in.
From this moment on all log messages made from inside ExecuteSlice() of this task will be assigned to the provided request context. Diagnostic contexts can be nested – second call to SetDiagCtx() sets new context of this task and next call to ReleaseDiagCtx() restores first context.
Definition at line 1201 of file logging.cpp.
References ctx, GetMemSize(), m_DiagChain, m_DiagChainSize, m_DiagCtx, malloc(), and SRV_FATAL.
Referenced by CNCActiveHandler::CopyPurge(), CNCActiveHandler::CopyPut(), CreateNewDiagCtx(), CNCActiveHandler::ProxyBList(), CNCActiveHandler::ProxyGetMeta(), CNCActiveHandler::ProxyGetSize(), CNCActiveHandler::ProxyHasBlob(), CNCActiveHandler::ProxyProlong(), CNCActiveHandler::ProxyRead(), CNCActiveHandler::ProxyReadLast(), CNCActiveHandler::ProxyRemove(), CNCActiveHandler::ProxySetValid(), CNCActiveHandler::ProxyWrite(), CNCActiveHandler::SearchMeta(), CNCActiveHandler::SetProxy(), CNCActiveHandler::SyncBlobsList(), CNCActiveHandler::SyncCancel(), CNCActiveHandler::SyncCommit(), CNCActiveHandler::SyncProlongOur(), CNCActiveHandler::SyncProlongPeer(), CNCActiveHandler::SyncSend(), CNCActiveHandler::SyncStart(), CNCActiveHandler::x_DoSyncGet(), CNCActiveHandler::x_ReadDataPrefix(), CNCActiveHandler::x_ReadHttpDataPrefix(), and CNCActiveHandler::x_ReplaceServerConn().
◆ SetPriority() void CSrvTask::SetPriority ( Uint4 prty ) inlineSet and retrieve task's priority.
TaskServer has simple notion of priority: all tasks by default have priority 1. For each slice of task with priority 2 TaskServer executes 2 slices of priority 1. For each slice of task with priority 3 TaskServer executes 3 tasks with priority 1 and 2 tasks with priority 2 (rounding goes up, error doesn't accumulate, i.e. for 2 tasks with priority 3 it executes 3 tasks with priority 2). And so on. But this rule works only if there are tasks with higher priorities in the queue. If only tasks with low priority are executing at the moment they will take all available time slices. Counting of already executed tasks and their priorities is done on a per-jiffy basis, i.e. if there were only high priority tasks for some time and then task with low priority appeared it probably will be executed within 0.01 second. That said priority system is not quite usable now because it needs things like priority inheritance from one task to the one created by it, priority combination in CSrvTransitionTask and probably some other mechanisms to work exactly as expected.
Definition at line 347 of file srv_inlines.hpp.
References m_Priority.
Referenced by CNCBlobVerManager::CNCBlobVerManager(), CNCActiveHandler::SetReservedForBG(), SNCBlobVerData::SNCBlobVerData(), CNCMessageHandler::x_CleanCmdResources(), and CNCMessageHandler::x_StartCommand().
◆ SetRunnable() void CSrvTask::SetRunnable ( bool boost =false
)
Set this task "runnable", i.e.
available for execution, having some pending work requiring some processing power. Call to this method guarantees that ExecuteSlice() will be called some time later. If another execution of ExecuteSlice() is in progress at the time of call to SetRunnable() then TaskServer will call ExecuteSlice() again some time after current ExecuteSlice() finishes. This behavior guarantees that if ExecuteSlice() somewhere checks for more available work, doesn't find it, decides to return and some other thread calls SetRunnable() at this moment task will have a chance to check for available work in next call to ExecuteSlice(). This method is thread-safe and can be called from any thread and any context.
Definition at line 618 of file scheduler.cpp.
References ACCESS_ONCE, AtomicCAS(), fTaskNeedTermination, fTaskQueued, fTaskRunnable, fTaskRunning, fTaskTerminated, GetCurThread(), m_LastThread, m_TaskFlags, RemoveTaskFromTimer(), s_AddTaskToQueue(), and s_FindQueueThread().
Referenced by CNCServer::CachingCompleted(), CNCActiveHandler::CheckCommandTimeout(), CheckConnectsTimeout(), CNCActiveHandler::ClientReleased(), CNCActiveHandler::CloseForShutdown(), CNCActiveSyncControl::CmdFinished(), CNCBlobVerManager::DeadTimeChanged(), SNCBlobVerData::DeleteThis(), CNCBlobVerManager::DeleteThis(), CNCLogCleaner::ExecuteSlice(), CLogWriter::ExecuteSlice(), SNCBlobVerData::ExecuteSlice(), CNCBlobAccessor::ExecuteSlice(), CNewFileCreator::ExecuteSlice(), CSrvStatesTask< CBlobCacher >::ExecuteSlice(), CNCBlobVerManager::FinalizeWriting(), CSrvTransitionTask::FinishTransition(), CNCBlobStorage::Initialize(), CWriteBackControl::Initialize(), CNCPeriodicSync::Initialize(), InitTimeMan(), CSrvSocketTask::InternalRunSlice(), CNCActiveHandler_Proxy::NeedToProxySocket(), CNCPeerControl::Peer(), SNCBlobVerData::RequestDataWrite(), CSrvSocketTask::RequestFlush(), SNCBlobVerData::RequestMemRelease(), CNCBlobVerManager::RequestMemRelease(), RequestStopListening(), CSrvTransitionTask::RequestTransition(), RunAfter(), s_DeleteOldestSockets(), s_DoDataProxy(), s_ExecuteTimerTicket(), s_GetNextWriteCoord(), s_NotifyConsumers(), s_QueueLogWrite(), s_RegisterClientEvent(), s_RegisterListenEvent(), s_StopSync(), CNCBlobStorage::SavePurgeData(), SNCBlobVerData::SetNotCurrent(), CNCActiveClientHub::SetStatus(), CSrvSocketTask::StartProcessing(), CBlobCacher::x_CacheNextRecord(), CNCActiveSyncControl::x_CheckSlotTheirSync(), CExpiredCleaner::x_CleanNextBucket(), CNCActiveHandler::x_CloseConn(), CBlobCacher::x_CreateInitialFile(), CExpiredCleaner::x_DeleteNextData(), CSpaceShrinker::x_DeleteNextFile(), SNCBlobVerData::x_ExecuteWriteAll(), CBlobCacher::x_FinishCaching(), CNCMessageHandler::x_FinishCommand(), CSpaceShrinker::x_FinishMoveRecord(), CSpaceShrinker::x_FinishSession(), CExpiredCleaner::x_FinishSession(), CBulkCleaner::x_FinishSession(), CNCActiveSyncControl::x_FinishSync(), CDiskFlusher::x_FlushNextFile(), CSpaceShrinker::x_MoveNextRecord(), CBlobCacher::x_PreCacheRecNums(), CSpaceShrinker::x_PrepareToShrink(), CNCMessageHandler::x_ReadBlobChunk(), CNCMessageHandler::x_ReadBlobChunkLength(), CNCActiveHandler::x_ReplaceServerConn(), and CNCActiveHandler::x_SetStateAndStartProcessing().
◆ Terminate() void CSrvTask::Terminate ( void ) virtual ◆ m_DiagChainNested diagnostic contexts of this task.
This variable is not NULL if this task have ever used nested contexts and contains array of context pointers with deepest context (the one assigned to task first) in the element 0, context set later in the element 1 etc.
Definition at line 221 of file srv_tasks.hpp.
Referenced by ReleaseDiagCtx(), SetDiagCtx(), and ~CSrvTask().
◆ m_DiagChainSize size_t CSrvTask::m_DiagChainSize ◆ m_DiagCtx ◆ m_LastActive int CSrvTask::m_LastActive ◆ m_LastThread ◆ m_Priority Uint4 CSrvTask::m_Priority ◆ m_TaskFlags ◆ m_TaskListHookHook to put this task into TSrvTaskList.
Definition at line 204 of file srv_tasks.hpp.
◆ m_Terminator ◆ m_TimerThe documentation for this class was generated from the following files:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4