IPC Frame too large issue
I am using relay mode to collect trace from some linux machines, mainly track_events from my workloads, the workload is a very busy program with overy 200 threads, and some of the events may carry some quite big data. the peak data rate of trace stream can get to 2-3MB/s. From the traced side , sometimes I can see the following error message: IPC Frame too large (size 131076) after several times, the recording size app will report Producer disconnected too many times; not reconnecting and the app trace is then muted for every
the reported size is always 128KB + 4 (131076), which is the limit of IPC frame size plus the header size, seems to hit a corner case
the reported size is always 128KB + 4 (131076)
This is expected as we cap the size (https://crsrc.org/c/third_party/perfetto/src/ipc/buffered_frame_deserializer.cc;l=103-104)
size_t next_frame_size =
std::min(static_cast<size_t>(payload_size), capacity_);
In relay, since there's no shmem between the two, the data itself gets serialized into the commit and sent over the socket. So this just means producer is emitting commit request larger than 128 KB (we dont know exactly how much higher) limit continuously which is causing the socket close and in turn the disconnect.
I am assuming you're using the latest perfetto build as I see some similar mitgations been done for this issue in https://r.android.com/3531576 and https://r.android.com/3531142
Reading the internal bug for the above fixes, I see that the the commit splitting is best effort. It caps the chunk payload but doesn't account for the patches or per chunk framing overhead.
Can you share:
- your trace config and some info on your data sources.
- the size of your largest events and your
page_size_kbconfig? - If you want to see the real frame size, you can add a temporary log in ClientImpl::SendFrame that should show the actual size.
Can you also try increasing page_size_kb and see if that helps.
I think the full fix for this issue was actually landed in http://github.com/google/perfetto/pull/5269. I suspect you are using an older version of Perfetto which does not have this fix.
Ahh I remember, there is one more fix needed https://github.com/google/perfetto/pull/5721/changes. This is available from v56.0
Actually I am using v56.1 SDK in my workloads now. I did see those related changesets, that's why I upgraded from v53 last week. Tests show no improvements. I think I may run into the case of size overflow for the last splitted commit request plus patches.
I am using the cpp sdk directly from the release page. the workload trace initialized with page size default value, 4kB
The trace config is something like this:
flush_period_ms: 2000
duration_ms: 60000
trace_all_machines: true
buffers {
size_kb: 32768
fill_policy: RING_BUFFER
}
buffers {
size_kb: 4096
fill_policy: RING_BUFFER
}
data_sources {
config {
name: "track_event"
target_buffer: 0
}
}
data_sources {
config {
name: "linux.process_stats"
target_buffer: 1
process_stats_config {
proc_stats_poll_ms: 2000
scan_all_processes_on_start: true
record_thread_names: true
record_process_age: true
record_process_runtime: true
}
}
}
data_sources {
config {
name: "linux.sys_stats"
target_buffer: 1
sys_stats_config {
meminfo_period_ms: 2000
vmstat_period_ms: 2000
stat_period_ms: 2000
devfreq_period_ms: 2000
cpufreq_period_ms: 2000
thermal_period_ms: 2000
cpuidle_period_ms: 2000
gpufreq_period_ms: 2000
}
}
}
Thanks for clarifying. I'm investigating to see if there's anything better we can do here.
Can you try bumping the shmem page size in in your TracingInitArgs.
args.shmem_page_size_hint_kb = 8;
// [Optional] Specifies the preferred size of each page in the shmem buffer.
// This is a trade-off between IPC overhead and fragmentation/efficiency of
// the shmem buffer in presence of multiple writer threads.
// Must be one of [4, 8, 16, 32].
uint32_t shmem_page_size_hint_kb = 0;
Bigger pages would reduce the number of chunks which might help. But this would also mean data loss can happen if too many writers. But worth a try.
We'll investigate more for a proper solution meanwhile.
https://github.com/google/perfetto/pull/6454 -> I think this should be a proper fix for this issue, taking into account patches as well. Would appreciate if you could try it out (see https://perfetto.dev/docs/instrumentation/tracing-sdk#getting-started for amalgamated command, https://perfetto.dev/docs/contributing/getting-started for cloning the repo, installing build deps)
I tried the patch and still see failure: I add some log in ClientImpl::SendFrame to catch oversized frame, see the failure is related to a log line: ClientImpl::SendFrame oversized buf.size=131221 chunks_to_move=16 chunks_to_patch=0 661 bytes more than the spliting check limit of (128K -512), beside the framing overhead, is there any other processing in the calling path which can extend the size? or is there any other path without calling to CommitDataWithSplitting?
beside the framing overhead, is there any other processing in the calling path which can extend the size?
Not that I'm aware of but I can do another pass to check.
or is there any other path without calling to CommitDataWithSplitting?
In the relay path there should not be.
beside the framing overhead, is there any other processing in the calling path which can extend the size?
Turns out there was another codepath which we did not consider: SMB scraping. It was was a separate codepath added in https://github.com/google/perfetto/commit/af41028bde, different to where the original SMB emulation code was added. And actually https://github.com/google/perfetto/pull/5721 was where it was fixed to actually go live.
I think in Android multi-VM workloads, the amount of tracing here is small enough we would never hit chunk splitting, you mention it only happens with high data rate workloads which matches the pattern this would happen in.
https://github.com/google/perfetto/pull/6482 should fix this and I hope be the last hole in the emulated SMB related codepaths (at least for now!).
https://github.com/google/perfetto/pull/6482 was merged, please try it out and let us know if it fixes things.
#6482 fixed my issue. thanks
Thanks for confirming! Fix will be included in v58!