Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Memory usage when upload file to DataLake gen2 #2140

Closed
Marusyk opened this issue Dec 29, 2020 · 10 comments
Closed

[Bug] Memory usage when upload file to DataLake gen2 #2140

Marusyk opened this issue Dec 29, 2020 · 10 comments
Labels

Comments

@Marusyk
Copy link

Marusyk commented Dec 29, 2020

  • List of NuGet packages and version that you are using:
    Microsoft.ApplicationInsights.AspNetCore 2.14.0
    Microsoft.ApplicationInsights.WorkerService 2.14.0
  • Runtime version (e.g. net461, net48, netcoreapp2.1, netcoreapp3.1, etc. You can find this information from the *.csproj file): netcoreapp3.1
  • Hosting environment (e.g. Azure Web App, App Service on Linux, Windows, Ubuntu, etc.): Linux Docker

I'm using Azure.Storage.Files.DataLake to send data every minute from my C# code with enabled Application Insights

services.AddApplicationInsightsTelemetryWorkerService();

There are a lot of operations with Datalake (now it's more than 5000 per hour).
I got a lot of memory usage of my application (each file ~150 bytes).

App without Application Insights enabled, after 3 days uptime: ~96Mb
App with Application Insights disabled, after 6 hours uptime: ~900Mb

Could you please suggest how to avoid AI memory leak?

I've tried but no success

public class DependencyTelemetryFilter : ITelemetryProcessor
    {
        private ITelemetryProcessor Next { get; set; }

        public DependencyTelemetryFilter(ITelemetryProcessor next)
        {
            Next = next;
        }

        public void Process(ITelemetry item)
        {
            if (item is DependencyTelemetry elem && elem.Contains("dfs.core.windows.net"))
            {
                return;
            }

            Next.Process(item);
        }
    }
@Marusyk
Copy link
Author

Marusyk commented Jan 7, 2021

/ping

@cijothomas
Copy link
Contributor

@Marusyk Could you share the code snippet used to make datalake calls? This issue can occur if the azure-data-lake sdk is used incorrectly as well, so it'd be great if you can share a small repro or code snippet doing datalake calls.

@Marusyk
Copy link
Author

Marusyk commented Jan 12, 2021

I'm using Azure.Storage.Files.DataLake to send data every minute from my C# code.

public class DataLakeStorage : IFileStorage
{
	private readonly DataLakeServiceClient _dataLakeClient;

	public DataLakeStorage(FileStorageOptions options)
	{
		var sharedKeyCredentials = new StorageSharedKeyCredential(options.AccountName, options.AccountKey);
		_dataLakeClient = new DataLakeServiceClient(new Uri($"https://{options.AccountName}.dfs.core.windows.net"), sharedKeyCredentials);
	}

	public async Task Add(string containerName, string path, string name, object data)
	{
		DataLakeFileSystemClient fileSystemClient = _dataLakeClient.GetFileSystemClient(containerName.ToLower());
		await fileSystemClient.CreateIfNotExistsAsync();

		DataLakeDirectoryClient directoryClient = fileSystemClient.GetDirectoryClient(path);
		DataLakeFileClient fileClient = await directoryClient.CreateFileAsync(name);

		await using var stream = new MemoryStream();
                await JsonSerializer.SerializeAsync(stream, data, data.GetType());
                stream.Position = 0;
                await fileClient.AppendAsync(stream, 0);
                await fileClient.FlushAsync(stream.Length);
	}
}

The DataLakeStorage is registered as a Singleton in web application.
Also, tried await fileClient.UploadAsync(stream, overwrite: true); instaed of

await fileClient.AppendAsync(stream, 0);
await fileClient.FlushAsync(stream.Length);

and added

 <PropertyGroup>
    <ServerGarbageCollection>false</ServerGarbageCollection>
  </PropertyGroup>

but the same result. It uses a lot of memory.

@cijothomas
Copy link
Contributor

@Marusyk The code does not appear to be concerning. I wanted to first see if this is related to #1867.
As this is not related, could you share a repro project for us to do deeper investigation?

@Marusyk
Copy link
Author

Marusyk commented Jan 14, 2021

@cijothomas
Actually, you need only this code with
services.AddApplicationInsightsTelemetryWorkerService(); to reprocude it.

call every few seconds:

await _instance.Add("containerName", DateTime.Now.ToString(), "name", new { Name = "name", Time = DateTime.Now });

@Marusyk
Copy link
Author

Marusyk commented Jan 28, 2021

any updates?
I upgraded my application to .NET 5 but it didn't help

@wesselkranenborg
Copy link

We are also facing this issue. We now implemented a regular restart of our service but that is far from ideal.

@Marusyk
Copy link
Author

Marusyk commented Feb 13, 2021

Hi @cijothomas, can anyone help with it?
It is not funny now. We got a huge memory usage when AppInsights enabled!!!

@Marusyk Marusyk changed the title [Question] Memory usage when upload file to DataLake gen2 [Bug] Memory usage when upload file to DataLake gen2 Feb 21, 2021
@github-actions
Copy link

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Dec 19, 2021
@Marusyk
Copy link
Author

Marusyk commented Dec 19, 2021

The issue is not fixed

@github-actions github-actions bot removed the stale label Dec 20, 2021
@Marusyk Marusyk closed this as not planned Won't fix, can't repro, duplicate, stale May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants