/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <chrono> #include <limits> #include <folly/Portability.h> #include <folly/concurrency/UnboundedQueue.h> #include <folly/executors/IOThreadPoolExecutor.h> #include <folly/executors/QueueObserver.h> #include <folly/experimental/io/EventBasePoller.h> #include <folly/io/async/EventBaseManager.h> #include <folly/synchronization/Baton.h> #include <folly/synchronization/RelaxedAtomic.h> #include <folly/synchronization/ThrottledLifoSem.h> #include <folly/synchronization/WaitOptions.h> namespace folly { /** * NOTE: This is highly experimental. Do not use. * * A pool of EventBases scheduled over a pool of threads. * * Intended as a drop-in replacement for folly::IOThreadPoolExecutor, but with a * substantially different design: EventBases are not pinned to threads, so it * is possible to have more EventBases than threads. EventBases that have ready * events can be scheduled on any of the threads in the pool, with the * scheduling governed by ThrottledLifoSem. * * This allows to batch the loops of multiple EventBases on a single thread as * long as each runs for a short enough time, reducing the number of wake-ups * and allowing for better load balancing across handlers. For example, we can * create a large number of EventBases processed by a smaller number of threads * and distribute the handlers. * * The number of EventBases is set at construction time and cannot be changed * later. The number of threads can be changed dynamically, but setting it to 0 * is not supported (otherwise no thread would be left to drive the EventBases) * and it is not useful to run more threads than EventBases, so that is not * supported either: attempting to set the number of threads to 0 or to a value * greater than numEventBases() (either in construction or using * setNumThreads()) will throw std::invalid_argument). */ class MuxIOThreadPoolExecutor : public IOThreadPoolExecutorBase { … }; } // namespace folly