go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/sync/dispatcher/doc.go (about)

     1  // Copyright 2019 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package dispatcher implements a super-charged version of a buffered channel
    16  // connected to a (potentially) parallelized work dispatcher.
    17  //
    18  // This can be used when you have a mismatch between the rate of production of
    19  // items and the rate of consumption of those items. For example:
    20  //
    21  //   - if you have a producer which constantly produces new world states,
    22  //     and you want to sink the latest one into a slow external RPC (but still
    23  //     do retries if no new state appears).
    24  //   - if you have bursty user data which you'd like to batch according to some
    25  //     maximum batch size, but you don't want the data to get too stale in case
    26  //     you don't hit that batch limit.
    27  //   - your external RPC can absorb almost infinite data, and the order of
    28  //     delivery doesn't matter, but you don't want to block the data producer.
    29  //   - etc.
    30  //
    31  // The dispatcher can be configured to:
    32  //   - Buffer a certain amount of work (with possible backpressure to the
    33  //     producer).
    34  //   - Batch pending work into chunks for the send function.
    35  //   - Drop stale work which is no longer important to send.
    36  //   - Enforce a maximum QPS on the send function (even with parallel senders).
    37  //   - Retry batches independently with configurable per-batch retry policy.
    38  package dispatcher