Created
March 13, 2012 02:04
-
-
Save darrelmiller/2026145 to your computer and use it in GitHub Desktop.
ThroughputMessageHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThroughputMessageHandler : DelegatingHandler | |
{ | |
private readonly ILogger _logger; | |
private Timer _timer; | |
private int _count; | |
public ThroughputMessageHandler(ILogger logger) | |
{ | |
_logger = logger; | |
_count = 0; | |
_timer = new Timer(new TimerCallback(timerCallback),null,1000,1000); | |
} | |
private void timerCallback(object state) | |
{ | |
_logger.Log("perf",TraceLevel.Verbose,() => _count + " req/sec"); | |
_count = 0; | |
} | |
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
return base.SendAsync(request, cancellationToken) | |
.ContinueWith((t) => { | |
lock (this) | |
{ | |
_count++; | |
} | |
return t.Result; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment