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

Per-handler memory estimation, more accurate estimate for metadata handler #5346

Merged
merged 20 commits into from
Jul 15, 2022

Commits on Jul 14, 2022

  1. Clarify behavior of process_next_response

    The behavior of process_next_response is worth clarifying as the
    returned future does not nececessarily wait for all enqueued respones
    to be finished before resolving.
    
    We also rename the method to better reflect its purpose.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    eea0de5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5f5c7c6 View commit details
    Browse the repository at this point in the history
  3. Release resources after the response is written

    Currently we release resources after the response is enqueued
    in connection_context and response processing is called, but it
    may not have been sent at this point as we require in-order responses
    but second-stage processing may happen out of order.
    
    In this change, we instead tunnel the resource object through to
    the place where the response is written, and release it there.
    
    FIxes redpanda-data#5278.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    d2bac6c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    5def3b7 View commit details
    Browse the repository at this point in the history
  5. Move max_api_key function to handlers header.

    This lets us share it with the request processing code which
    would also like to do type list based manipulation of the
    request types.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    79fe3a5 View commit details
    Browse the repository at this point in the history
  6. Introduce KafkaApiHandlerAny concept

    We already had concepts for one-phase and two-phase handlers,
    and this concept is simply the union of those two handler
    concepts, i.e., "any" type of handler.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    2e4dd22 View commit details
    Browse the repository at this point in the history
  7. Rename handler to single_stage_handler

    We wish to reclaim the name handler for the generic handler interface
    introduced in the next change.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    0c8a6e9 View commit details
    Browse the repository at this point in the history
  8. Introduce type-erased handler interface

    This is a polymorphic handler class (abstract class with virtual
    methods), as well as concrete instantiations of the interface for each
    of the existing handlers, which can be looked up by API key.
    
    This lets us treat handlers generically without resorting to template
    functions which must be specialized for each handler type.
    
    This reduces code bloat significantly as we do not duplicate code paths
    for our ~45 handler types.
    
    For example, requests.cc.o drops from ~11 MB to ~5 MB after it is
    switched to the any_handler approach.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    d533df6 View commit details
    Browse the repository at this point in the history
  9. Add handler_interface unit tests

    The handler_interface already gets good functional coverage as it is
    added to the core request path in requests.cc, but we also include
    this unit test with basic coverage.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    f80e99d View commit details
    Browse the repository at this point in the history
  10. Update request handling to use polymorphic handler

    Preceding changes in this series introduced a runtime polymorphic
    handler class, and this change switches most of the request handling
    to use it.
    
    In particular, we replace the large switch on API key which dispatches
    to a template method to a lookup of the handler method and virtual
    dispatch.
    
    Some handlers that need special processing like the authentication/SASL
    related ones still use the old approach for now.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    12d4379 View commit details
    Browse the repository at this point in the history
  11. Add support for memory estimation to handlers

    Currently we use  single memory estimate for all kafka request types,
    but different API calls may use wildly different amounts of memory.
    
    This change allows each handler to perform an API-specific calculation
    instead.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    38be81c View commit details
    Browse the repository at this point in the history
  12. Use handler specific memory estimate

    In connection_context, we now use the handler-specific initial memory
    use estimate, rather than a single estimate for every handler type.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    5a9ca08 View commit details
    Browse the repository at this point in the history
  13. Move session_resouces object to top level

    The session_resources type was a private member of
    connection_context, but as we want to use it more
    broadly, move it out as a standalone public class.
    
    Additionally, pass it by shared_pointer in preparation
    for later changes will feed it into requests.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    958b933 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    213b671 View commit details
    Browse the repository at this point in the history
  15. Introduce handler template for two-stage handlers

    Single-stage handlers have a handler template which means that handler
    objects can be declared in a single line specifying their api object,
    min and max API versions.
    
    This change extends this nice concept to two-stage handlers as well.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    d645c7a View commit details
    Browse the repository at this point in the history
  16. Add the connection context to the memory estimator

    Passing the connection context to the estimator allows the
    estimator to use the various subsystems to estimate the memory
    use of a given request.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    bbea197 View commit details
    Browse the repository at this point in the history
  17. Use a better estimator for metadata requests

    Currently we estimate that metadata requests take 8000 + rsize * 2 bytes
    of memory to process, where rsize is the size of the request. Since
    metadata requests are very small, this end up being roughly 8000 bytes.
    
    However, metadata requests which return information about every
    partition and replica may easily be several MBs in size.
    
    To fix this for metadata requests specifically, we use a new more
    conservative estimate which uses the current topic and partition
    configuration to give an upper bound on the size.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    c218c2b View commit details
    Browse the repository at this point in the history
  18. Include broker list in metadata estimation

    Prior to this change, we used only the topic and partition data to estimate
    the size of the metadata response. Now, we also include the approximate
    size of the broker metadata portion of the response, which may
    be important if the list of brokers is very large or they have very long
    hostnames.
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    6cb5a71 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    f649f7f View commit details
    Browse the repository at this point in the history
  20. Add NOLINT to use of operator[]

    We already check the bounds so the cpp core guideline presumably
    does not apply and we don't want to pay the price for the additional
    bounds check inside at().
    travisdowns committed Jul 14, 2022
    Configuration menu
    Copy the full SHA
    fd6353f View commit details
    Browse the repository at this point in the history