Time-Segment Invocation Statistics Plugin
Recommended usage scenarios
- Production
- Performance analysis
Introduction
TimeRangeInOut is a time-segment invocation statistics plugin. Its main focus is action call counts across daily time segments.
- It can collect data for all 24 hours, or only specified hours.
- It can collect per-minute stats within each hour, or specified minute segments (for example, only
0~30, and ignore30~60).
Developers can use this data to analyze call frequency by time segment, so they can identify when player activity is highest.
With this data, you can understand request traffic distribution across different times. Based on these statistics, you can scale up machines before peak hours and scale down after peak hours.
Print Preview
Under default configuration, hourly invocation counts are collected and printed like this:
2023-11-29 action invocation count total [10000]
0:00 total 431;
1:00 total 416;
2:00 total 421;
3:00 total 414;
4:00 total 441;
5:00 total 423;
6:00 total 407;
7:00 total 395;
8:00 total 410;
9:00 total 413;
10:00 total 378;
11:00 total 411;
12:00 total 380;
13:00 total 413;
14:00 total 417;
15:00 total 416;
16:00 total 400;
17:00 total 430;
18:00 total 471;
19:00 total 440;
20:00 total 405;
21:00 total 430;
22:00 total 414;
23:00 total 424;
The default configuration already covers most scenarios.
How to Use
BarSkeletonBuilder builder = ...;
builder.addInOut(new TimeRangeInOut());
More Configuration Examples
Precise to Specific Hour
In the example below, we override createListenerTimeRangeHourList
to listen only to invocation stats at hours 12, 19, and 20, ignoring other hours.
private void setListener(TimeRangeInOut inOut) {
inOut.setListener(new TimeRangeInOut.ChangeListener() {
@Override
public List<TimeRangeInOut.TimeRangeHour> createListenerTimeRangeHourList() {
return List.of(
this.createListenerTimeRangeHour(12),
this.createListenerTimeRangeHour(19),
this.createListenerTimeRangeHour(20)
);
}
});
}
Since only 12, 19, and 20 are monitored, output includes:
- Full-day invocation total
- Details for these three time points
2023-11-29 action invocation count total [10000]
12:00 total 442;
19:00 total 410;
20:00 total 422;
Precise to Specific Minute Segment
In the example below, we override createListenerTimeRangeMinuteList
for fine-grained statistics within each hour using minute ranges.
private void setListener(TimeRangeInOut inOut) {
inOut.setListener(new TimeRangeInOut.ChangeListener() {
@Override
public List<TimeRangeInOut.TimeRangeHour> createListenerTimeRangeHourList() {
return List.of(
this.createListenerTimeRangeHour(12),
this.createListenerTimeRangeHour(19),
this.createListenerTimeRangeHour(20)
);
}
@Override
public List<TimeRangeInOut.TimeRangeMinute> createListenerTimeRangeMinuteList() {
return List.of(
TimeRangeInOut.TimeRangeMinute.create(0, 29),
TimeRangeInOut.TimeRangeMinute.create(30, 59)
);
}
});
}
Since 0~29 and 30~59 minute ranges are monitored, the plugin outputs:
- Full-day invocation total
- Details for three time points
- Minute-range stats within each hour
2023-11-29 action invocation count total [10000]
12:00 total 449; - [0~29 min 236] - [30~59 min 213]
19:00 total 435; - [0~29 min 227] - [30~59 min 208]
20:00 total 385; - [0~29 min 175] - [30~59 min 210]
Minute-range default behavior is inclusive on both ends. The example below collects only minute 0, 1, and 59.
private void setListener(TimeRangeInOut inOut) {
inOut.setListener(new TimeRangeInOut.ChangeListener() {
@Override
public List<TimeRangeInOut.TimeRangeMinute> createListenerTimeRangeMinuteList() {
return List.of(
TimeRangeInOut.TimeRangeMinute.create(0, 0),
TimeRangeInOut.TimeRangeMinute.create(1, 1),
TimeRangeInOut.TimeRangeMinute.create(59, 59)
);
}
});
}
Daily 0:00 Callback
TimeRangeDay is a one-day statistics object containing all time-segment statistics for that day.
The plugin triggers callbackYesterday every day at 0:00, passing yesterday's TimeRangeDay object.
Developers can sync this data to logs, DB, or other systems in that method.
- code 5: yesterday's full-day statistics object
private void setListener(TimeRangeInOut inOut) {
inOut.setListener(new TimeRangeInOut.ChangeListener() {
@Override
public void callbackYesterday(TimeRangeInOut.TimeRangeDay timeRangeYesterday) {
System.out.println(timeRangeYesterday);
}
});
}