Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
cd1acd9b
Commit
cd1acd9b
authored
Jun 27, 2023
by
ruyun.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
并发限制
parent
40851855
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
2 deletions
+74
-2
performance/Performance.Api/Configurations/RateLimitConfig.cs
+18
-0
performance/Performance.Api/Program.cs
+1
-1
performance/Performance.Api/Startup.cs
+3
-1
performance/Performance.Api/limit.json
+51
-0
performance/Performance.Infrastructure/Performance.Infrastructure.csproj
+1
-0
No files found.
performance/Performance.Api/Configurations/RateLimitConfig.cs
0 → 100644
View file @
cd1acd9b
using
AspNetCoreRateLimit
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
namespace
Performance.Api.Configurations
{
public
static
class
RateLimitConfig
{
public
static
IServiceCollection
AddCustomRateLimit
(
this
IServiceCollection
services
,
IConfiguration
configuration
)
{
services
.
Configure
<
IpRateLimitOptions
>(
configuration
.
GetSection
(
"IpRateLimiting"
));
services
.
Configure
<
IpRateLimitPolicies
>(
configuration
.
GetSection
(
"IpRateLimitPolicies"
));
services
.
AddInMemoryRateLimiting
();
services
.
AddSingleton
<
IRateLimitConfiguration
,
RateLimitConfiguration
>();
return
services
;
}
}
}
performance/Performance.Api/Program.cs
View file @
cd1acd9b
...
@@ -35,7 +35,7 @@ public static void Main(string[] args)
...
@@ -35,7 +35,7 @@ public static void Main(string[] args)
var
env
=
context
.
HostingEnvironment
;
var
env
=
context
.
HostingEnvironment
;
config
.
AddJsonFile
(
"appsettings.json"
,
true
,
true
);
config
.
AddJsonFile
(
"appsettings.json"
,
true
,
true
);
config
.
AddJsonFile
(
$"appsettings.
{
env
.
EnvironmentName
}
.json"
,
true
,
true
);
config
.
AddJsonFile
(
$"appsettings.
{
env
.
EnvironmentName
}
.json"
,
true
,
true
);
config
.
AddJsonFile
(
$"RateLimitConfig
.json"
,
true
,
true
);
config
.
AddJsonFile
(
"limit
.json"
,
true
,
true
);
})
})
.
UseUrls
(
"http://*:5001"
)
.
UseUrls
(
"http://*:5001"
)
.
UseStartup
<
Startup
>()
.
UseStartup
<
Startup
>()
...
...
performance/Performance.Api/Startup.cs
View file @
cd1acd9b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.Globalization
;
using
System.Globalization
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Text
;
using
System.Text
;
using
AspNetCoreRateLimit
;
using
FluentScheduler
;
using
FluentScheduler
;
using
FluentValidation
;
using
FluentValidation
;
using
FluentValidation.AspNetCore
;
using
FluentValidation.AspNetCore
;
...
@@ -84,6 +85,7 @@ public void ConfigureServices(IServiceCollection services)
...
@@ -84,6 +85,7 @@ public void ConfigureServices(IServiceCollection services)
// service repository
// service repository
services
.
AddDependencyInjectionConfiguration
();
services
.
AddDependencyInjectionConfiguration
();
services
.
AddCustomRateLimit
(
Configuration
);
// signalr
// signalr
services
.
AddSignalR
(
hubOptions
=>
services
.
AddSignalR
(
hubOptions
=>
...
@@ -119,8 +121,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
...
@@ -119,8 +121,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
{
app
.
UseStatusCodePagesWithReExecute
(
"/error/{0}"
);
app
.
UseStatusCodePagesWithReExecute
(
"/error/{0}"
);
}
}
app
.
UseExpirationLimit
();
app
.
UseExpirationLimit
();
app
.
UseIpRateLimiting
();
app
.
UseRouting
();
app
.
UseRouting
();
...
...
performance/Performance.Api/limit.json
0 → 100644
View file @
cd1acd9b
{
"IpRateLimiting"
:
{
"EnableEndpointRateLimiting"
:
true
,
"StackBlockedRequests"
:
false
,
"RealIpHeader"
:
"X-Real-IP"
,
"ClientIdHeader"
:
"X-ClientId"
,
"HttpStatusCode"
:
429
,
//
本地测试需要取消白名单IP
"IpWhitelist"
:
[
"127.0.0.1"
,
"::1/10"
,
"192.168.0.0/24"
],
"EndpointWhitelist"
:
[
"get:/api/license"
],
"ClientWhitelist"
:
[
"dev-id-1"
,
"dev-id-2"
],
"QuotaExceededResponse"
:
{
"Content"
:
"{{
\"
code
\"
:429,
\"
message
\"
:
\"
您访问过于频繁,请稍后重试...
\"
}}"
,
"ContentType"
:
"application/json"
,
"StatusCode"
:
429
},
"GeneralRules"
:
[
{
"Endpoint"
:
"post:/api/assess/category/issue/confirm"
,
"Period"
:
"1s"
,
"Limit"
:
1
},
{
"Endpoint"
:
"post:*"
,
"Period"
:
"1s"
,
"Limit"
:
10
},
{
"Endpoint"
:
"get:*"
,
"Period"
:
"1s"
,
"Limit"
:
100
},
{
"Endpoint"
:
"*"
,
"Period"
:
"15m"
,
"Limit"
:
100
},
{
"Endpoint"
:
"*"
,
"Period"
:
"12h"
,
"Limit"
:
1000
},
{
"Endpoint"
:
"*"
,
"Period"
:
"7d"
,
"Limit"
:
10000
}
]
}
}
\ No newline at end of file
performance/Performance.Infrastructure/Performance.Infrastructure.csproj
View file @
cd1acd9b
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
<PackageReference Include="NPOI" Version="2.5.5" />
<PackageReference Include="NPOI" Version="2.5.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.2" />
<PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
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