Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable alignment to FastSerializer #1560

Merged

Conversation

josalem
Copy link
Contributor

@josalem josalem commented Jan 27, 2022

IOStreamStreamReader had a hard coded 8 byte alignment. EventPipe streams do not have any alignment requirements (save for some 4 byte alignments inside blocks). This means that blocks can have sizes that are not aligned. EventPipeEventSource will not dispatch events read from the stream until reads complete. In live cases where these blocks are unaligned, but no new data is coming down the pipe, the reader can attempt to enforce the alignment and end up blocking until new data arrives. This results in latency for event dispatch. For infrequent events, this can be a long period of time causing users to think they haven't received events.

For example:

EventBlock 1, EventBlock 2, and EventBlock 3 all arrive with aligned lengths. EventBlock 4 arrives with an unaligned length. Until more data arrives on the stream, none of the events in EventBlock 4 will be dispatched to the user.

This change adds a configuration switch for changing the alignment of the reader. The default is the old behavior (8 byte alignment) and the live reading for EventPipe was changed to 1 byte alignment.

Changing to an alignment of 1 uncovered a bug where calling Goto(StreamLabel) with a label greater than the alignment length would cause the subsequent read to return bytes from the wrong position in the stream. Up until now, this wasn't an issue for EventPipe because all Goto calls were for jumps < 4 due to the internal alignment, which is always less than 8.

This patch also fixes that bug.

TODO: tag all the issues this will close. I believe there are issues in dotnet/runtime, dotnet/diagnostics, dotnet/dotnet-monitor, and microsoft/perfview that are tracking this issue.

CC @tommcdon @jander-msft @wiktork

* Fix unseen bug where Goto(label) where label > alignment size would cause reads at the wrong position
@josalem josalem self-assigned this Jan 27, 2022
Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM

src/FastSerialization/FastSerialization.cs Outdated Show resolved Hide resolved
src/TraceEvent/TraceEvent.Tests/EventPipeParsing.cs Outdated Show resolved Hide resolved
Co-authored-by: Noah Falk <noahfalk@users.noreply.github.com>
Copy link
Member

@brianrob brianrob left a comment

Choose a reason for hiding this comment

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

Overall, LTGM. A couple of small things.

John Salem added 2 commits January 28, 2022 10:02
…om:josalem/perfview into dev/josalem/allow-unaligned-stream-reading
@brianrob brianrob merged commit 6c26a03 into microsoft:main Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants