You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

resource_quota.h 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/codegen/config.h>
  22. #include <grpcpp/impl/codegen/grpc_library.h>
  23. namespace grpc
  24. {
  25. /// ResourceQuota represents a bound on memory and thread usage by the gRPC
  26. /// library. A ResourceQuota can be attached to a server (via \a ServerBuilder),
  27. /// or a client channel (via \a ChannelArguments).
  28. /// gRPC will attempt to keep memory and threads used by all attached entities
  29. /// below the ResourceQuota bound.
  30. class ResourceQuota final : private grpc::GrpcLibraryCodegen
  31. {
  32. public:
  33. /// \param name - a unique name for this ResourceQuota.
  34. explicit ResourceQuota(const std::string& name);
  35. ResourceQuota();
  36. ~ResourceQuota() override;
  37. /// Resize this \a ResourceQuota to a new size. If \a new_size is smaller
  38. /// than the current size of the pool, memory usage will be monotonically
  39. /// decreased until it falls under \a new_size.
  40. /// No time bound is given for this to occur however.
  41. ResourceQuota& Resize(size_t new_size);
  42. /// Set the max number of threads that can be allocated from this
  43. /// ResourceQuota object.
  44. ///
  45. /// If the new_max_threads value is smaller than the current value, no new
  46. /// threads are allocated until the number of active threads fall below
  47. /// new_max_threads. There is no time bound on when this may happen i.e none
  48. /// of the current threads are forcefully destroyed and all threads run their
  49. /// normal course.
  50. ResourceQuota& SetMaxThreads(int new_max_threads);
  51. grpc_resource_quota* c_resource_quota() const
  52. {
  53. return impl_;
  54. }
  55. private:
  56. ResourceQuota(const ResourceQuota& rhs);
  57. ResourceQuota& operator=(const ResourceQuota& rhs);
  58. grpc_resource_quota* const impl_;
  59. };
  60. } // namespace grpc
  61. #endif // GRPCPP_RESOURCE_QUOTA_H