Hi Demis,
I want to migrate an existing service that runs on Windows to Kubernetes.
The current service runs on .net 4.7. thanks to a good SS architecture, it was very easy to convert the service to .net core 3.1.
But the results were not what was expected
Requests have become several times slower, and sometimes the service restarts. It seems to me that the problem is that the number of threads in .net core is limited and we need to use an asynchronous programming approach.
Configuration of the service:
.UseKestrel(options => {
options.Limits.MaxRequestBodySize = null;
options.Limits.MaxConcurrentConnections = null;
options.Limits.MaxConcurrentUpgradedConnections = null;
options.AllowSynchronousIO = false;
})
//Against memory leaks in kubernetes
<PropertyGroup>
<ServerGarbageCollection>false</ServerGarbageCollection>
</PropertyGroup>
Our files were stored on a hard disk drive, and when migrate .net core, we moved the files to s3.
And the problem may be in them.
public async Task Any(GetFile request) {
var objectResponse = await S3Storage.ProxyObjectAsync(bucketName, filePath);
await ServiceExtensions.ResponseFromS3Async(Response, objectResponse);
}
public class S3Storage {
private const string AccessKey = "key";
private const string SecretKey = "secret";
private const string ServiceUrl = "url";
private readonly AmazonS3Client _client;
private S3Storage() {
AWSCredentials credentials = new BasicAWSCredentials(AccessKey, SecretKey);
var config = new AmazonS3Config {
ServiceURL = ServiceUrl
};
_client = new AmazonS3Client(credentials, config);
}
public static S3Storage Instance { get; } = new S3Storage();
public async Task<GetObjectResponse> ProxyObjectAsync(string bucketName, string filePath) {
return await _client.GetObjectAsync(new GetObjectRequest {
BucketName = bucketName,
Key = filePath
});
}
}
public static class ServiceExtensions {
public static async Task ResponseFromS3Async(IResponse res, GetObjectResponse s3Response, bool asAttachment = false) {
var statusCode = (int) s3Response.HttpStatusCode;
res.StatusCode = statusCode == 0 ? (int) HttpStatusCode.OK : statusCode;
res.ContentType = s3Response.Headers.ContentType;
res.AddHeader(
HttpHeaders.ContentDisposition,
$"{(asAttachment ? "attachment;" : "")}{HttpExt.GetDispositionFileName(Path.GetFileName(s3Response.Key))}"
);
if (s3Response.ContentLength >= 0)
res.SetContentLength(s3Response.ContentLength);
await s3Response.ResponseStream.CopyToAsync(res.OutputStream);
res.EndHttpHandlerRequest(true);
}
}
The problem is that when requesting ‘GetFile’ even the simplest query Select () (the table contains 100 rows of two columns) is executed in 1000 milliseconds but when there are no queries Select() is executed in 30 milliseconds.
Please tell me if there are any known factors that I did not consider? I understand that this is a specific case and may not be entirely related to the SS, but in fact it is a case that other people may encounter when migrating. I want to thank you in advance for your time!