Skip to content

EntropyEngine::Networking::BatchManager

Batches high-frequency property updates for efficient network transmission. More…

#include <BatchManager.h>

Name
structStats
Get statistics.
Name
~BatchManager()
voidupdateProperty(PropertyHash hash, PropertyType type, const PropertyValue & value)
Update a property value (will be batched).
voidsetOnBatchDropped(std::function< void(size_t)> callback)
Set callback for dropped batches (backpressure monitoring).
voidsetBatchInterval(uint32_t intervalMs)
Set the batch interval.
voidprocessBatch()
Process pending updates and send a batch.
StatsgetStats() const
size_tgetPendingCount() const
Get number of pending updates waiting to be batched.
uint32_tgetBatchInterval() const
Get current batch interval.
voidflush()
Force an immediate flush of pending updates.
BatchManager(SessionHandle session, uint32_t batchIntervalMs =16)
Construct a batch manager for a network session.
class EntropyEngine::Networking::BatchManager;

Batches high-frequency property updates for efficient network transmission.

Design:

  • Global batch rate (configurable, default 16ms for 60Hz)
  • Accumulates property updates in a map (automatic deduplication)
  • Uses WorkContract for scheduling batch processing
  • Sends batches on unreliable channel
  • Dynamic rate adjustment on backpressure (drop old batches, reduce rate)
  • Property hashes are provided by caller (never computed internally)

Usage:

ConnectionManager connMgr(1024);
SessionManager sessMgr(&connMgr, 512);
auto session = sessMgr.createSession(connection);
auto batcher = std::make_shared<BatchManager>(session);
// Caller computes hash from entity metadata
auto hash = computePropertyHash(entityId, componentType, "transform.position");
batcher->updateProperty(hash, PropertyType::Vec3, position);
// Application schedules periodic batch processing
// Example using std::thread and timer:
std::atomic<bool> running{true};
std::thread batchThread([&]() {
while (running) {
batcher->processBatch();
std::this_thread::sleep_for(std::chrono::milliseconds(batcher->getBatchInterval()));
}
});
// Optional: Set callback for dropped batches (backpressure monitoring)
batcher->setOnBatchDropped([](size_t droppedCount) {
LOG_WARNING("Dropped batch with " + std::to_string(droppedCount) + " updates due to backpressure");
});
~BatchManager()
void updateProperty(
PropertyHash hash,
PropertyType type,
const PropertyValue & value
)

Update a property value (will be batched).

Parameters:

  • hash Property hash (computed by caller)
  • type Property type
  • value Property value

Accumulates the update. If the same property is updated multiple times before the next batch, only the latest value is kept.

void setOnBatchDropped(
std::function< void(size_t)> callback
)

Set callback for dropped batches (backpressure monitoring).

Parameters:

  • callback Function called when a batch is dropped, receives the number of updates that were dropped
void setBatchInterval(
uint32_t intervalMs
)

Set the batch interval.

Parameters:

  • intervalMs New interval in milliseconds
void processBatch()

Process pending updates and send a batch.

This should be called periodically by the application (e.g., via work contracts). The application is responsible for scheduling this at the desired batch interval.

Stats getStats() const
size_t getPendingCount() const

Get number of pending updates waiting to be batched.

inline uint32_t getBatchInterval() const

Get current batch interval.

void flush()

Force an immediate flush of pending updates.

Alias for processBatch(). Useful for critical updates that can’t wait.

explicit BatchManager(
SessionHandle session,
uint32_t batchIntervalMs =16
)

Construct a batch manager for a network session.

Parameters:

  • session The session handle to send batches through
  • batchIntervalMs Batch interval in milliseconds (default 16ms = 60Hz)

Note: The application is responsible for calling processBatch() periodically, typically by scheduling work contracts in a loop.


Updated on 2026-01-26 at 16:50:32 -0500