resource_quota.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. //
  3. // Copyright 2016 gRPC authors.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. //
  18. #ifndef GRPCPP_RESOURCE_QUOTA_H
  19. #define GRPCPP_RESOURCE_QUOTA_H
  20. struct grpc_resource_quota;
  21. #include <grpcpp/impl/grpc_library.h>
  22. #include <grpcpp/support/config.h>
  23. namespace grpc {
  24. /// ResourceQuota represents a bound on memory and thread usage by the gRPC
  25. /// library. A ResourceQuota can be attached to a server (via \a ServerBuilder),
  26. /// or a client channel (via \a ChannelArguments).
  27. /// gRPC will attempt to keep memory and threads used by all attached entities
  28. /// below the ResourceQuota bound.
  29. class ResourceQuota final : private grpc::internal::GrpcLibrary {
  30. public:
  31. /// \param name - a unique name for this ResourceQuota.
  32. explicit ResourceQuota(const TString& name);
  33. ResourceQuota();
  34. ~ResourceQuota() override;
  35. /// Resize this \a ResourceQuota to a new size. If \a new_size is smaller
  36. /// than the current size of the pool, memory usage will be monotonically
  37. /// decreased until it falls under \a new_size.
  38. /// No time bound is given for this to occur however.
  39. ResourceQuota& Resize(size_t new_size);
  40. /// Set the max number of threads that can be allocated from this
  41. /// ResourceQuota object.
  42. ///
  43. /// If the new_max_threads value is smaller than the current value, no new
  44. /// threads are allocated until the number of active threads fall below
  45. /// new_max_threads. There is no time bound on when this may happen i.e none
  46. /// of the current threads are forcefully destroyed and all threads run their
  47. /// normal course.
  48. ResourceQuota& SetMaxThreads(int new_max_threads);
  49. grpc_resource_quota* c_resource_quota() const { return impl_; }
  50. private:
  51. ResourceQuota(const ResourceQuota& rhs);
  52. ResourceQuota& operator=(const ResourceQuota& rhs);
  53. grpc_resource_quota* const impl_;
  54. };
  55. } // namespace grpc
  56. #endif // GRPCPP_RESOURCE_QUOTA_H