Skip to content

Kafka codec: precompute request size before serialization, so we do n…#6862

Merged
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
adamkotwasinski:kafka-serializer-improvements
May 10, 2019
Merged

Kafka codec: precompute request size before serialization, so we do n…#6862
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
adamkotwasinski:kafka-serializer-improvements

Conversation

@adamkotwasinski
Copy link
Contributor

…ot have buffer copying

Description:
Current request serialization code uses a temporary buffer to compute size of request (it's a non-trivial operation, driven by request's api version present in EncodingContext).
This PR finally adds .computeSize method to request and underlying structures, it's pretty similar to serialization after all (use template overload for primitive type/array/string OR just call computeSize on "rich object").

Identified in #4950 (comment)

The alternative was to use Buffer::Instance::prepend, but then we require the user to provide empty buffer to codec.

Risk Level: Low (new Kafka codec that's not active anyways)
Testing: automated tests
Docs Changes: n/a
Release Notes: n/a

…ot have buffer copying

Signed-off-by: Adam Kotwasinski <adam.kotwasinski@gmail.com>
@adamkotwasinski
Copy link
Contributor Author

/wait until tests pass

@adamkotwasinski
Copy link
Contributor Author

@mattklein123 Could you please take a look when you have a moment? Thank you!

@mattklein123 mattklein123 self-assigned this May 8, 2019
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM with small comments. Thank you!

/wait

* Computes the size of this request, if it were to be serialized.
* @return serialized size of request
*/
virtual size_t computeSize() const PURE;
Copy link
Member

Choose a reason for hiding this comment

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

Prefer explicit types. uint64_t or uint32_t ? Same elsewhere.

: AbstractRequest{request_header}, data_{data} {};

/**
* Compute the size of request, what includes both the request header and its real data.
Copy link
Member

Choose a reason for hiding this comment

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

s/what/which ?

EncodingContext encoder{-1};
encoder.encode(data_len, output_); // Encode data length into result.
output_.add(data_buffer); // Copy encoded data into result.
const int32_t size = htobe32(message.computeSize());
Copy link
Member

Choose a reason for hiding this comment

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

unsigned? Same elsewhere where applicable.

@repokitteh-read-only
Copy link

🙀 Error while processing event:

evaluation error
error: load("github.com/repokitteh/modules/review.star") error: module load error
🐱

Caused by: a #6862 (review) was submitted by @mattklein123.

see: more, trace.

…stead of size_t

Signed-off-by: Adam Kotwasinski <adam.kotwasinski@gmail.com>
@adamkotwasinski
Copy link
Contributor Author

/wait until tests pass

@adamkotwasinski
Copy link
Contributor Author

@mattklein123 size_t replaced with uint32_t in new & existing serialization code, as per Kafka spec

@mattklein123
Copy link
Member

@adamkotwasinski in the future please make sure the waiting label is cleared when you are ready for me to look at it otherwise the PR doesn't show up in my typical workflow. Thank you.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Awesome, thanks.

@mattklein123 mattklein123 merged commit 31485b5 into envoyproxy:master May 10, 2019
@adamkotwasinski adamkotwasinski deleted the kafka-serializer-improvements branch May 10, 2019 18:56
mpuncel added a commit to mpuncel/envoy that referenced this pull request May 10, 2019
* master: (88 commits)
  upstream: Null-deref on TCP health checker if setsockopt fails  (envoyproxy#6793)
  ci: switch macOS CI to azure pipelines (envoyproxy#6889)
  os syscalls lib: break apart syscalls used for hot restart (envoyproxy#6880)
  Kafka codec: precompute request size before serialization, so we do n… (envoyproxy#6862)
  upstream: move static and strict_dns clusters to dedicated files (envoyproxy#6886)
  Rollforward of api: Add total_issued_requests to Upstream Locality and Endpoint Stats. (envoyproxy#6692) (envoyproxy#6784)
  fix explicit constructor in copy-initialization (envoyproxy#6884)
  stats: use tag iterator rather than constructing the tag-array and searching that. (envoyproxy#6853)
  common: use unscoped build target in generate_version_linkstamp (envoyproxy#6877)
  Addendum to envoyproxy#6778 (envoyproxy#6882)
  ci: add minimum Linux build for Azure Pipelines (envoyproxy#6881)
  grpc: utilities for inter-converting grpc::ByteBuffer and Buffer::Instance. (envoyproxy#6732)
  upstream: allow excluding hosts from lb calculations until initial health check (envoyproxy#6794)
  stats: prevent unused counters from leaking across hot restart (envoyproxy#6850)
  network filters: add `injectDataToFilterChain(data, end_stream)` method to network filter callbacks (envoyproxy#6750)
  delete things that snuck back in (envoyproxy#6873)
  config: scoped rds (2b): support delta APIs in ConfigProvider framework (envoyproxy#6781)
  string == string! (envoyproxy#6868)
  config: add mssing imports to delta_subscription_state (envoyproxy#6869)
  protobuf: add missing default case to enum (envoyproxy#6870)
  ...

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
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