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

Developers using ILogger have improved performance #48619

Open
1 of 2 tasks
Tracked by #5929
sebastienros opened this issue Oct 26, 2020 · 5 comments
Open
1 of 2 tasks
Tracked by #5929

Developers using ILogger have improved performance #48619

sebastienros opened this issue Oct 26, 2020 · 5 comments
Assignees
Labels
area-Extensions-Logging tenet-performance Performance related issue User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@sebastienros
Copy link
Member

sebastienros commented Oct 26, 2020

Improve performance characteristics of Logging.

Areas of interest:

  • Improve Console logging performance
  • Minimize impact of no-op logging (without requiring to clear providers)
  • Define percentage overhead for logging providers

Issues:

@sebastienros
Copy link
Member Author

@sebastienros
Copy link
Member Author

TODO: Add Fortunes/EF/MVC/HTTPS scenario with loggers turned on (nothing logged) and re-enable Json Middleware with logging.

@shirhatti shirhatti transferred this issue from dotnet/aspnetcore Feb 22, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-Extensions-Logging untriaged New issue has not been triaged by the area owner labels Feb 22, 2021
@ghost
Copy link

ghost commented Feb 22, 2021

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

Improve performance characteristics of Logging.

Areas of interest:

  • Improve Console logging performance
  • Minimize impact of no-op logging (without requiring to clear providers)
  • Define percentage overhead for logging providers
Author: sebastienros
Assignees: davidfowl
Labels:

area-Extensions-Logging, untriaged

Milestone: -

@shirhatti shirhatti changed the title [Performance] Logging Developers using ILogger have improved performance Feb 22, 2021
@shirhatti shirhatti added the User Story A single user-facing feature. Can be grouped under an epic. label Feb 22, 2021
@maryamariyan maryamariyan added this to the 6.0.0 milestone Feb 25, 2021
@maryamariyan maryamariyan added tenet-performance Performance related issue and removed untriaged New issue has not been triaged by the area owner labels Feb 25, 2021
@maryamariyan
Copy link
Member

maryamariyan commented Mar 26, 2021

Minimize impact of no-op logging (without requiring to clear providers)

Here's an isolated benchmark for no-op vs disabled use case: (I had to loop 1000 times for a proper diff to show up between the two cases)

For benchmarks

        [Benchmark]
        public void LogDebug()
        {
            for (int i = 0; i < 1000; i++)
                _logger.LogDebug(@"Connection id '{connectionId}', range [{start}..{end}], options {options}", ConnectionId, Start, End, Options);
        }


        [Benchmark]
        public void LoggerMessage()
        {
            for (int i = 0; i < 1000; i++)
                _loggerMessage2(_logger, ConnectionId, Start, End, Options, null);
        }

where loggerMessage2 is:

        private static Action<ILogger, string, long, long, int, Exception?> _loggerMessage2 = LoggerMessage.Define<string, long, long, int>(LogLevel.Debug,
                            eventId: 381,
                            formatString: @"Connection id '{connectionId}', range [{start}..{end}], options {options}");

and _logger as ConsoleLogger,

Using

// noop (logger.IsEnabled(LogLevel.Debug) will be false here)
                .AddLogging(logBuilder =>
                {
                    logBuilder.AddConsole().SetMinimumLevel(LogLevel.Information);
                })

We get

|            Method |      Mean |    Error |   StdDev |   Gen 0 | Gen 1 | Gen 2 | Allocated |
|------------------ |----------:|---------:|---------:|--------:|------:|------:|----------:|
|          LogDebug | 143.60 us | 2.859 us | 7.225 us | 16.1133 |     - |     - |  128000 B |
|     LoggerMessage |  11.36 us | 0.226 us | 0.338 us |       - |     - |     - |         - |

and using

// disabled
                .AddLogging(logBuilder =>
                {
                    logBuilder.ClearProviders();
                })

we get:

|            Method |       Mean |     Error |    StdDev |   Gen 0 | Gen 1 | Gen 2 | Allocated |
|------------------ |-----------:|----------:|----------:|--------:|------:|------:|----------:|
|          LogDebug | 137.765 us | 2.7482 us | 7.0939 us | 16.1133 |     - |     - |  128000 B |
|     LoggerMessage |   9.170 us | 0.2059 us | 0.6007 us |       - |     - |     - |         - |

link to gist

Here's another perf report using Microsoft.Crank: https://gist.github.com/maryamariyan/06370e90cdc7809037de59a88662d9d6

Define percentage overhead for logging providers

These benchmarks show there is definitely a perf overhead with adding logging providers

@maryamariyan
Copy link
Member

I added more benchmarks and a little report with a set of logging use cases here: https://gist.github.com/maryamariyan/0bad4136655f344bf203274e5b7431b4

cc: @gfoidl @adamsitnik @davidfowl @sebastienros

@maryamariyan maryamariyan modified the milestones: 6.0.0, 7.0.0 Jul 23, 2021
@eerhardt eerhardt modified the milestones: 7.0.0, Future Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-Logging tenet-performance Performance related issue User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests

5 participants