Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
89bbc2c3
Commit
89bbc2c3
authored
Aug 16, 2018
by
Ge Jun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify interface of ConcurrencyLimiter
parent
5e1cabb1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
25 deletions
+9
-25
concurrency_limiter.h
src/brpc/concurrency_limiter.h
+9
-25
No files found.
src/brpc/concurrency_limiter.h
View file @
89bbc2c3
...
...
@@ -24,15 +24,15 @@
namespace
brpc
{
class
ConcurrencyLimiter
:
public
Destroyable
{
class
ConcurrencyLimiter
{
public
:
ConcurrencyLimiter
()
:
_max_concurrency
(
0
)
{}
virtual
~
ConcurrencyLimiter
(
)
{}
// This method should be called each time a request comes in. It returns
// false when the concurrency reaches the upper limit, otherwise it
// returns true. Normally, when OnRequested returns false, you should
// return an ELIMIT error directly.
virtual
bool
OnRequested
()
=
0
;
virtual
bool
OnRequested
(
int
current_concurrency
)
=
0
;
// Each request should call this method before responding.
// `error_code' : Error code obtained from the controller, 0 means success.
...
...
@@ -41,29 +41,13 @@ public:
// still need to call OnResponded.
virtual
void
OnResponded
(
int
error_code
,
int64_t
latency_us
)
=
0
;
// Returns the current maximum concurrency. Note that the maximum
// concurrency of some ConcurrencyLimiters(eg: `auto', `gradient')
// is dynamically changing.
int
max_concurrency
()
{
return
_max_concurrency
;
};
// Expose internal vars. NOT thread-safe.
// Return 0 on success, -1 otherwise.
virtual
int
Expose
(
const
butil
::
StringPiece
&
prefix
)
=
0
;
// Create/destroy an instance.
// Caller is responsible for Destroy() the instance after usage.
virtual
ConcurrencyLimiter
*
New
()
const
=
0
;
virtual
~
ConcurrencyLimiter
()
{}
// Create ConcurrencyLimiter* and coredump if it fails.
// Caller is responsible for Destroy() the instance after usage.
static
ConcurrencyLimiter
*
CreateConcurrencyLimiterOrDie
(
const
AdaptiveMaxConcurrency
&
max_concurrency
);
// Returns the latest max_concurrency.
// The return value is only for logging.
virtual
int
MaxConcurrency
()
=
0
;
protected
:
//
Assume int32_t is atomic in x86
int32_t
_max_concurrency
;
// Create an instance from the amc
//
Caller is responsible for delete the instance after usage.
virtual
ConcurrencyLimiter
*
New
(
const
AdaptiveMaxConcurrency
&
amc
)
const
=
0
;
};
inline
Extension
<
const
ConcurrencyLimiter
>*
ConcurrencyLimiterExtension
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment