Я устанавливаю ограничитель параллелизма следующим образом:
Код: Выделить всё
services.AddRateLimiter(options =>
{
options.AddConcurrencyLimiter(policyName: concurrencyPolicyName, options =>
{
options.PermitLimit = 160;
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
options.QueueLimit = 160;
});
options.OnRejected = async (context, token) =>
{
context.HttpContext.Response.StatusCode = 503;
await context.HttpContext.Response.WriteAsync("The service is currently handling too many requests. Please try again later... ", cancellationToken: token);
};
});
.
.
.
endpoints.MapGrpcService().RequireRateLimiting(concurrencyPolicyName);
Код: Выделить всё
service My_Service {
rpc Get (GetMessage) returns (GetReply);
rpc Set (SetMessage) returns (SetReply);
}
Код: Выделить всё
endpoints.MapGrpcService().RequireRateLimiting(concurrencyPolicyName);
Подробнее здесь: https://stackoverflow.com/questions/787 ... -rpc-calls
Мобильная версия