bug 1218576 - Request an immediate batch send when the batch size hits a high water mark. r=gfritzsche

We've now seen an OOM trying to grow the accumulations array during a test
suite. The g*Accumulations arrays do grow unboundedly in size waiting for the
IPC timer to fire, so we should put a size bound as well as a time bound to
trigger the batch send.

The current size bound is 5K elements. This was chosen out of a hat.

MozReview-Commit-ID: 5HeWdbLfN03
This commit is contained in:
Chris H-C
2016-09-08 10:15:15 -04:00
parent 079b09b927
commit a0fde28cee

View File

@@ -225,6 +225,11 @@ const mozilla::Telemetry::ID kRecordingInitiallyDisabledIDs[] = {
// timeliness and performance (see bug 1218576)
const uint32_t kBatchTimeoutMs = 2000;
// To stop growing unbounded in memory while waiting for kBatchTimeoutMs to
// drain the g*Accumulations arrays, request an immediate flush if the arrays
// manage to reach this high water mark of elements.
const size_t kAccumulationsArrayHighWaterMark = 5 * 1024;
} // namespace
@@ -1315,6 +1320,11 @@ internal_RemoteAccumulate(mozilla::Telemetry::ID aId, uint32_t aSample)
if (!gAccumulations) {
gAccumulations = new nsTArray<Accumulation>();
}
if (gAccumulations->Length() == kAccumulationsArrayHighWaterMark) {
NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
TelemetryHistogram::IPCTimerFired(nullptr, nullptr);
}));
}
gAccumulations->AppendElement(Accumulation{aId, aSample});
internal_armIPCTimer();
return true;
@@ -1330,6 +1340,11 @@ internal_RemoteAccumulate(mozilla::Telemetry::ID aId,
if (!gKeyedAccumulations) {
gKeyedAccumulations = new nsTArray<KeyedAccumulation>();
}
if (gKeyedAccumulations->Length() == kAccumulationsArrayHighWaterMark) {
NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
TelemetryHistogram::IPCTimerFired(nullptr, nullptr);
}));
}
gKeyedAccumulations->AppendElement(KeyedAccumulation{aId, aSample, aKey});
internal_armIPCTimer();
return true;