Economy Batching

circle-check

What is Batching?

Instead of processing each currency gain immediately (which requires a database operation), the batch processor collects all currency gains over a period and processes them as a single batch.

Performance Impact

circle-info

Example

Without Batching:

  • 100 players online

  • Each player kills 1 mob every 5 seconds

  • Each mob drops 3 different currencies

  • Result: 3,600 database transactions per minute, but instant updates via placeholders.

With Batching (40 ticks = 2 seconds):

  • Same scenario

  • Batched every 2 seconds

  • Result: ~90 database transactions per minute, however placeholders don't update instantly.


Configuration

Location

Batch processing settings are in config.yml:

circle-exclamation

How It Works

1

Currency Gain

When a player earns currency (e.g., killing a mob):

2

Queued for Batching

Instead of immediately updating the database, the gains are queued:

3

Additional Gains

If the player earns more currency before the batch processes:

4

Batch Processing

After interval-ticks (e.g., 40 ticks = 2 seconds), all queued gains are processed:


Tuning Recommendations

High Player Count (100+ players)


Low Player Count (< 20 players)


Events & API

Currency Gain Event

The PlayerCurrencyGainEvent is fired when the batch processes:

circle-exclamation

Manual Flushing (API)

Developers can manually flush a player's batch:


Common Questions

chevron-rightWill players see currency updates immediately?hashtag

This depends on your settings, if you decide not to do batch updates, then the placeholder updates are in real time.

chevron-rightWhat happens if the server crashes before batching?hashtag

Currency gains queued in the batch may be lost if the server crashes before the next batch interval. However, this window is typically only 1-3 seconds.

circle-info

To minimize risk, use a shorter interval-ticks (e.g., 20-40 ticks). We may implement a safety mechanism for this in the future, but no guarantee.

chevron-rightCan I disable batching for specific currencies?hashtag

No, batching applies to all economies globally. It's an all-or-nothing setting.

chevron-rightDoes batching affect admin commands?hashtag

Admin commands (/money give, /money set, etc.) bypass batching and update balances immediately.

Last updated