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

Forwards logs to the server if server supports it #361

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jabberrock
Copy link
Contributor

@jabberrock jabberrock commented Nov 11, 2024

  1. Adds a new class LogQueue which stores up to a fixed number of log messages in a circular buffer. It stores up to 30 pending log messages of max 255B each which takes up 7.4K of statically allocated memory. There is no dynamic allocation.
  2. Whenever Logger is called, the log message is pushed into the LogQueue.
  3. Whenever the Connection loop is run, it will try to send one pending message to the server.

Note that sending logs is best-effort since it's over UDP.

Related PRs:
SlimeVR/SolarXR-Protocol#153
SlimeVR/SlimeVR-Server#1234

image

1. Adds a new class LogQueue which stores up to a fixed number of log messages in a circular buffer.
2. Whenever Logger is called, the log message is pushed into the LogQueue.
3. Whenever the Connection loop is run, it will try to send one pending message to the server.

Note that sending logs is best-effort since it's over UDP.
else
{
// Overwrite the last message
setMessageAt(m_Count - 1, OverflowMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would probably be a good idea to consider if overriding the first messages would make more sense in this context (tho honestly will never happen)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're probably right, it's better to keep the newest logs rather than the oldest logs.

Copy link
Contributor Author

@jabberrock jabberrock Nov 12, 2024

Choose a reason for hiding this comment

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

Do you think it's even necessary to send an [OVERFLOW] message? I'm worried once we get to overflow territory, every message we send to the server will just be [OVERFLOW].

Maybe if we can't keep up, we just silently drop (the oldest) messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed this by silently dropping earliest message.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think an overflow message would be particularly useful, and in theory it would override another message, would it not?

void setMessageAt(int offset, const char* message);

static constexpr size_t MaxMessages = 100;
static constexpr size_t MaxMessageLength = std::numeric_limits<uint8_t>::max();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd have this defined as a publicly available constexpr variable inside logger or something, that way it isn't duplicated in multiple cases of the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't really feel duplicated. This constant here limits the size of the LogQueue. The check I added in Connections::sendShortString limits the string that can be sent on that wire format.

It feels weird for Connections to reference logging size, or for LogQueue to reference wire format size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

E.g. If we wanted to send longer messages, then we'd have to switch to Connections::sendLongString, which has a very different limit. We wouldn't use std::numeric_limits<ulong_t>::max() for our MaxMessageLength.

else
{
// Overwrite the last message
setMessageAt(m_Count - 1, OverflowMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably worth considering, if maybe overriding the oldest message would make more sense in this context (though it will never happen hopefully).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed this by silently dropping earliest message.

src/logging/LogQueue.h Outdated Show resolved Hide resolved
@jabberrock
Copy link
Contributor Author

I reduced the max messages from 100 to 30 because I was seeing some OOM panics. Have not seen any more OOM since then, but I'm curious how the memory budget is allocated.

// Server can parse bundle packets with compact headers and packed IMU rotation/acceleration frames:
// - `PACKET_BUNDLE_COMPACT` = 101 (0x65),
// - `PACKET_ROTATION_AND_ACCELERATION` = 23 (0x17).
PROTOCOL_BUNDLE_COMPACT_SUPPORT,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

2 participants