Skip to main content

Jobs & the TaskScheduler

Where: Base/include/rbx/TaskScheduler.h, Base/rbx/TaskScheduler*.cpp, App/v8datamodel/DataModelJob.cpp, App/v8datamodel/BaseRenderJob.cpp, …

The 2016 engine replaced a naive main loop with a job-based scheduler: all recurring work is expressed as TaskScheduler::Job objects that a central singleton (RBX::TaskScheduler) executes on a pool of worker Threads (Base/rbx/TaskScheduler.Thread.cpp).

The scheduler​

From Base/include/rbx/TaskScheduler.h:

  • TaskScheduler — "A singleton object responsible for scheduling the execution TaskScheduler.Jobs." It keeps sleeping/waiting intrusive lists of jobs and implements a cyclic executive mode (fixed frame cadence — cyclicExecutiveLoopId, cyclicExecutiveWaitForNextFrame, DataModel30fpsThrottle) alongside best-effort non-cyclic jobs.
  • TaskScheduler::Job (Base/rbx/TaskScheduler.Job.cpp) — unit of recurring work with its own timing, priority and sleep logic.
  • TaskScheduler::Thread — worker threads that pull runnable jobs.

Arbiters​

The interesting part is TaskScheduler::Arbiter:

class Arbiter {
virtual std::string arbiterName() = 0;
virtual bool areExclusive(Job* job1, Job* job2) = 0;
virtual bool isThrottled() = 0;
...
};

An arbiter declares that two jobs must never run at the same time (for example: two jobs that both need to mutate the DataModel). This is how the engine gets parallelism between rendering, physics and networking without letting anything corrupt shared state — instead of one global lock, exclusivity is declared per job pair and tracked with activity meters (ActivityMeter), which also powers job-profiling statistics.

The important jobs​

JobFileRole
DataModelJobApp/v8datamodel/DataModelJob.cppSteps the DataModel: scripts (Heartbeat & co.), services, simulation steps
BaseRenderJob / RenderJobApp/v8datamodel/BaseRenderJob.cpp, WindowsClient/RenderJob.cppFrames the render pipeline (see Rendering)
Physics steppingApp/v8world/*Stage.cpp, kernel stagesWorld simulation (see Physics)
ContentProviderJobApp/util/ContentProviderJob.cppBackground asset downloads
NetworkOwnerJobNetwork/NetworkOwnerJob.cppRecomputes network ownership of assemblies
MovementHistoryJobNetwork/MovementHistoryJob.cppRecords physics movement history for replication
GamePerfMonitorNetwork/GamePerfMonitor.cppPerformance counters for the server

Profiling & observation​

Base/rbx/Profiler.cpp, ProcessPerfCounter.cpp plus the ActivityMeter on arbiters feed the in-engine profiling surfaces (RenderStats, microprofile-style tooling; the roadmap lists "advanced profiling tools" as a future enhancement).