Don't Use Protobuf for Telemetry

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • Protobuf.NET

    Protocol Buffers library for idiomatic .NET

  • > Protobuf-java is a little heavy [...] Just depending on the library adds 1.6MB and nearly 700 classes before you even generate your own message classes.

    By comparison, protobuf-net [1] is about 260KB and 68 classes. Python's [2] is a 1MB package download (with source).

    Why's the Java one so big?

    [1] https://github.com/protobuf-net/protobuf-net

    [2] https://pypi.org/project/protobuf

  • taoup

    The Tao of Unix Programming (Ruby-powered ANSI colored fortunes)

  • Optimization: Prototype before polishing. Get it working before you optimize it. - Eric S. Raymond, The Art of Unix Programming (2003)

    The First Rule of Program Optimization: Don't do it. - Michael Jackson

    The Second Rule of Program Optimization (for experts only): Don't do it yet. - Michael Jackson

    Spell create with an 'e'. - Ken Thompson (referring to design regrets on the UNIX creat(2) system call and the fallacy of premature optimization)

    The No Free Lunch theorem: Any two optimization algorithms are equivalent when their performance is averaged across all possible problems (if an algorithm performs well on a certain class of problems then it necessarily pays for that with degraded performance on the set of all remaining problems).

    ... quotes via https://github.com/globalcitizen/taoup

    FWIW at my company we do embedded robotics, use ridiculously underpowered processors with very limited capabilities, and still prefer use HTTP as it is well understood, has good tooling and is easy for everyone to deal with, which reduces real world business costs vs. custom wire-level formats.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • protobag

  • In many cases you do indeed want or need to use Protobuf for telemetry or other time-series data. The Protobuf RecordIO / TFRecord formats are very unhelpful for this use case.

    Enter Protobag: https://github.com/StandardCyborg/protobag

    Protobag is a library that helps you write and read time-series and other collections of Protobuf data using the standard Tar and Zip archives as containers. Protobag also includes code for leveraging self-describing messages to embed schemas in archives so that you never have data on disk that you can't read. Hope somebody finds Protobag helpful.

  • upb

    a small protobuf implementation in C

  • > Google's implementations, at least C++ and Java, are a bunch of bloated crap (or maybe they're very good, but for a use case that I haven't yet encountered).

    As someone who has been working on protobuf-related things for >10 years, including creating a size-focused implementation (https://github.com/protocolbuffers/upb), and has been working on the protobuf team for >5 years, I have a few thoughts on this.

    I think it is true that protobuf C++ could be a lot more lean than it currently is. That's why I created upb (above) to begin with. But there's also a bit more to this story.

    The protobuf core runtime is split into two parts, "lite" and "full". Basically the full runtime contains reflection support, while the lite runtime omits it. The full runtime is much larger than the lite runtime. If you don't need runtime reflection for your protos, it's better to use "lite" by using "option optimize_for = LITE_RUNTIME" in your .proto file (https://developers.google.com/protocol-buffers/docs/proto#op...). That will cut out a huge amount of overhead in your binary. On the downside, you won't get functionality that requires reflection, including text format, JSON, or DebugString().

    In addition to this, even the lite runtime can get "lighter" if you compile your binary to statically link the runtime and strip unused symbols with -ffunction-sections/-fdata-sections and gc-sections in the linker. Some parts of the lite runtime are only used in unusual situations, like ExtensionSet which is only used if your protos use proto2 extensions (https://developers.google.com/protocol-buffers/docs/proto#ex...). If you avoid this stuff, the lite runtime is quite light.

    However, there is also the issue of the generated code size. The size of the generated code is generally quite large, even for lite. You are getting a generated parser, serializer, CopyFrom(), MergeFrom(), etc for every message you define. If your schema is of any size, this quickly adds up and can dwarf the size of the actual runtime. For this reason, C++ also supports "option optimize_for = CODE_SIZE" which does everything reflectively instead of generating code. This means you pay the fixed size hit from the full runtime, but the generated code size is much smaller. On the downside, "optimize_for = CODE_SIZE" has a severe speed penalty.

    I have long had the goal of making https://github.com/protocolbuffers/upb competitive with protobuf C++ in speed while achieving much smaller code size. With the benefit of 10 years of hindsight and many wrong turns, upb is meeting and even surpassing these goals. It is an order of magnitude smaller, both in the core runtime and the generated code, and after some recent experiments it is beginning to significantly surpass it in speed also (I want to publish these results soon, but the code is on this branch: https://github.com/protocolbuffers/upb/pull/310).

    upb has downsides that prevent it from being fully "user ready" yet: the API is still not 100% stable, there is no C++ API for the generated code yet (and C APIs for protobuf are relatively verbose and painful), it has a bunch of legacy APIs sitting around that I am just on the verge of being able to finally delete, and it doesn't support proto2 extensions yet. On the upside, it is 100% conformant on every other protobuf feature, it has full binary and JSON support, it supports reflection if you want it but also lets you omit it for code size savings.

    I hope 2021 is a year when I'll be able to publish more about these results, and when upb will be a more viable choice for users who want a smaller protobuf implementation.

  • Protobuf

    Protocol Buffers - Google's data interchange format

  • > I'm was quite surprised you didnt offer your own stringview implementation (or something similar) the last time I looked at protobuf.

    We sort of do actually: https://github.com/protocolbuffers/protobuf/blob/master/src/...

    The internal version of protobuf lets you switch individual string fields to string_view using [ctype=STRING_PIECE], but migrating the default away from std::string is mainly just an enormous migration challenge.

    Internally we also do something slightly nuts: we break the encapsulation of std::string so that we can point it to arena-allocated memory (we then "steal" the memory back before the destructor runs). We can only afford to do this internally, where the implementation of std::string is known. The real long-term solution is to move to string_view.

  • test-infra

    Test infrastructure for the Kubernetes project.

  • Here's a minimal Python protobuf parser that can extract basic information in about 50 LOC.

    https://github.com/kubernetes/test-infra/blob/master/guberna...

  • bloaty

    Bloaty: a size profiler for binaries

  • I used my tool Bloaty, which parses the ELF and DWARF information in the binary: https://github.com/google/bloaty

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • protozero

    Minimalist protocol buffer decoder and encoder in C++

  • Its a shame you can't share the code, we could really do with a modern C++ implementation. Having said that, protozero looks very interesting [1], need to find some time to look into it.

    [1] https://github.com/mapbox/protozero

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts