Giter Club home page Giter Club logo

Comments (5)

bruno-garcia avatar bruno-garcia commented on June 12, 2024 1

I recommend measuring this (taking a memory heap dump) since guessing what might be the culprit can be a risky/time consuming game

from sentry-dotnet.

jamescrosswell avatar jamescrosswell commented on June 12, 2024

One thought about this is that we clone the scope every time a new span or transaction is created. It would be interesting to know how much of the memory that Sentry is allocating is in the form of Scopes (vs TransactionTracers/SpanTracers).

Assuming all the cloned scopes are significant though, there might be a way to track the differences between child scopes and parent scopes rather than creating entirely new long lived clones.

So one solution, for example, rather than setting properties directly on the scopes of child spans, we could associate one or more actions with them that could be used to determine the effective scope: List<Action<Scope>> _scopeModifications. The actual/effective scope for each span could be retrieved by taking a clone of the root scope and applying any scope modifications (similar to playing back the events in an EventSourcing architecture)... so you'd grab an ephemeral instance of the Span.Scope only when you needed to access it (probably it would have the lifetime of an individual method call... rather than staying in memory for as long as the transaction was running).

This would reduce memory consumption... it would come at the cost of speed though (as every time you needed to access the scope, you'd have to take a fresh clone of the root scope and apply the scope modifications).

Potentially we could give users the ability to choose whether they wantMemoryOptimizedTracing or CPUOptimizedTracing... depending on which was the more important constraint in their particular business context.

from sentry-dotnet.

jamescrosswell avatar jamescrosswell commented on June 12, 2024

from sentry-dotnet.

jamescrosswell avatar jamescrosswell commented on June 12, 2024

When profiling applications I've noticed that, unsurprisingly, where memory is being consumed depends very much on what th application is doing. So if, for example, I get artillery to call this endpoint a few hundred times, most of the memory is consumed by allocations of breadcrumb (and it's various composite properties):

                    endpoints.MapGet("/breadcrumbs", async context =>
                    {
                        void BreadcrumbCountdown(int countdown)
                        {
                            SentrySdk.AddBreadcrumb(countdown.ToString());
                            if (--countdown == 0)
                            {
                                return;
                            }

                            BreadcrumbCountdown(countdown);
                        }

                        BreadcrumbCountdown(100);
                        await context.Response.WriteAsync("Hello Breadcrumbs!");
                    });

On the other hand, if I have artillery call this, it's all about the scope:

                    endpoints.MapGet("/scopes", async context =>
                    {
                        void ScopeCountdown(int countdown)
                        {
                            using (SentrySdk.PushScope())
                            {
                                SentrySdk.ConfigureScope(scope =>
                                {
                                    scope.SetExtra("countdown", countdown);
                                });

                                if (--countdown == 0)
                                {
                                    return;
                                }

                                ScopeCountdown(countdown);
                            }
                        }

                        ScopeCountdown(100);
                        await context.Response.WriteAsync("Hello Scopes!");
                    });

I'm wondering if it's possible to get some memory snapshots from real world applications that aren't so biased. It'd be really illuminating to know what was taking up the most memory in the customer application that triggered this issue, for example... and that will depend entirely on what their application is doing and how they've instrumented it with Sentry. Have they used lots of breadcrumbs? Do they have deep scope trees? Are they heavily using Tags? It could be any number of things, but it feels like we're stabbing in the dark a bit without data from real world applications.

from sentry-dotnet.

bitsandfoxes avatar bitsandfoxes commented on June 12, 2024

Considering this closed until proven otherwise.
Optimizations that happened:

from sentry-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.