Skip to content

Delay metric serialisation until flush #271

Description

@pudiva

Hi dogstaters! 👋

Our website makes extensive use of dogstatsd-ruby to the point we had to optimise it for performance, and we'd like to discuss the possibility of upstreaming some of it.

During performance investigations, we found out that dogstatsd-ruby serialises metrics immediately whenever we make any metric calls, such as @dogstats.increment, and this behaviour has been increasing our app latency. To work around it, we created a wrapper object that intercept those metric calls and instead of performing them immediately, stores their arguments in an internal array and only makes the actual calls to dogstatsd-ruby after the HTTP response is sent, saving us ~20ms in latency.

Thus we'd like to propose a patch to make dogstatsd-ruby even more lightweight by delaying metric serialisation until flush time. For the multi-threaded case, serialisation would happen on the sender thread, and for the single-threaded case, it would still happen on the main thread, but only when flushing, which could be done after response.

What do you think?
✨ ✨ ✨

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions