I have a piece of code deployed in Azure Container Apps that primarily copies the file from the staging Azure blob storage to the final Azure blob storage and computes the SHA256 hash.
However, I have noticed the Azure container app often crashes with cpu reaching 100+% while computing the hash for large files (5GB, 10GB, ... 25GB).
I am using the following code for computing the hash.
private async Task<string> ComputHashAsync(BlobClient blobClient)
{
using (var sha256 = SHA256.Create())
{
using (var blobStream = await blobClient.OpenReadAsync())
{
using (var bufferedStream = new BufferedStream(blobStream, this._computeHashBufferSize))
{
var hash = sha256.ComputeHash(bufferedStream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
}
with the _computeHashBufferSize set to 2097152.
Any suggestions to improve the above code to safeguard from causing the container app crash with higher CPU usage?