Skip to content

improve: batched trackers update#418

Draft
jprzimba wants to merge 4 commits intomainfrom
improve-trackers
Draft

improve: batched trackers update#418
jprzimba wants to merge 4 commits intomainfrom
improve-trackers

Conversation

@jprzimba
Copy link
Copy Markdown
Collaborator

Tracker Functions Optimization

Batching has been implemented for tracker functions to reduce I/O and allocations:

Changes Implemented:

  1. Batching Data Structure:
  • BatchedTrackerData to accumulate loot, supply, impact, and input data
  • Control flags to avoid multiple schedules
  1. Optimized Functions:
  • sendLootStats: Accumulates items and values, schedules flush in 250ms
  • updateSupplyTracker: Accumulates items and values, schedules flush in 250ms
  • updateImpactTracker: Accumulates combat data, schedules flush in 250ms
  • updateInputAnalyzer: Accumulates input data, schedules flush in 250ms
  1. Flush Function:
  • flushBatchedTrackerData: Sends aggregated data and clears the buffer
  • Sends aggregated metrics (reduces I/O)
  • Sends individual data to client/party (keeps functionality)

Benefits:

  • I/O Reduction: Metrics sent in batches instead of per event
  • Fewer Allocations: Data accumulated in reusable structures
  • Coalescence: Multiple events in the same tick are processed together
  • Controlled Latency: Flush in 250ms maintains responsiveness

Impact:

  • Significantly reduces I/O overhead in high-activity situations (intense combat, mass loot)
  • Keeps original functionality intact
  • Improves overall server performance under load

@jprzimba jprzimba added the enhancement New feature or request label Oct 14, 2025
@jprzimba jprzimba changed the title fix: batched trackers updated improve: batched trackers updated Oct 14, 2025
self->flushBatchedTrackerData();
},
"Player::flushBatchedTrackerData"
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you sum the amount, it'll create a bug with the "max-dps" and "all-time high"
But if you don’t sum it, you’ll send all of them separately so it’ll be the same, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sending impact events separately is the right behavior, and it’s what the code already does.


// Send aggregated loot stats
if (batchedTrackerData.lootValue > 0) {
g_metrics().addCounter("player_loot", batchedTrackerData.lootValue, { { "player", getName() } });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated info in g_metrics()
g_metrics().addCounter("player_loot", value, { { "player", getName() } });

- Previous behavior: flushBatchedTrackerData emitted a single aggregated counter using batchedTrackerData.lootValue ( src/creatures/players/player.cpp:1756 ).
- Change: Emit one counter per loot item using its computed value (coins or “Lootmonger” sell price) during the loop over lootItems . Removed the aggregated emission.
- Result: Metrics reflect each loot event individually and avoid double-reporting caused by batch aggregation.
@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added the Stale label Dec 18, 2025
Decreased the tracker batch event delay from 250ms to 50ms for faster updates. Simplified the loot value calculation in flushBatchedTrackerData by aggregating loot value directly and sending metrics only if lootValue is positive. Also added calls to sendStats() and sendSkills() in onCreatureAppear.
@jprzimba jprzimba changed the title improve: batched trackers updated improve: batched trackers update Jan 8, 2026
@github-actions github-actions bot removed the Stale label Jan 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2026

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added the Stale label Feb 8, 2026
@jprzimba jprzimba marked this pull request as draft March 15, 2026 13:29
@github-actions github-actions bot removed the Stale label Mar 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added the Stale label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants