Skip to content

Commit

Permalink
wip: update
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Aug 31, 2024
1 parent 588fa40 commit c8e2c84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/GZCTF/Middlewares/RateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ await context.HttpContext.Response.WriteAsJsonAsync(
});
options.AddTokenBucketLimiter(nameof(LimitPolicy.Submit), o =>
{
o.TokenLimit = 200;
o.TokensPerPeriod = 100;
o.TokenLimit = 100;
o.TokensPerPeriod = 50;
o.ReplenishmentPeriod = TimeSpan.FromSeconds(5);
});
}
Expand Down
14 changes: 6 additions & 8 deletions src/GZCTF/Services/FlagChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@ public class FlagChecker(
IServiceScopeFactory serviceScopeFactory) : IHostedService
{
CancellationTokenSource TokenSource { get; set; } = new();
const int MaxWorkerCount = 6;
const int MaxWorkerCount = 4;

internal static int GetWorkerCount()
{
// if RAM < 2GiB or CPU <= 2, return 1
// if RAM < 4GiB or CPU <= 4, return 2
// if RAM < 6GiB or CPU <= 8, return 4
// if RAM < 2GiB or CPU <= 3, return 1
// if RAM < 4GiB or CPU <= 6, return 2
// otherwise, return 4
var memoryInfo = GC.GetGCMemoryInfo();
double freeMemory = memoryInfo.TotalAvailableMemoryBytes / 1024.0 / 1024.0 / 1024.0;
var cpuCount = Environment.ProcessorCount;

if (freeMemory < 2 || cpuCount <= 2)
if (freeMemory < 2 || cpuCount <= 3)
return 1;
if (freeMemory < 4 || cpuCount <= 4)
if (freeMemory < 4 || cpuCount <= 6)
return 2;
if (freeMemory < 6 || cpuCount <= 8)
return 4;
return MaxWorkerCount;
}

Expand Down

0 comments on commit c8e2c84

Please sign in to comment.