Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Date header performance #220

Merged
merged 3 commits into from
Sep 25, 2015
Merged

Date header performance #220

merged 3 commits into from
Sep 25, 2015

Conversation

DamianEdwards
Copy link
Member

#163

Uses a Timer to update a shared date string that is sent for the "Date" response header.
The Timer doesn't start until a request comes in, then shuts off after an idle period of no requests, and finally starts again if requests come in again.

NOTE: This is now rebased on #207 so until that gets merged, this PR contains all those changes too.

@dnfclas
Copy link

dnfclas commented Sep 24, 2015

Hi @DamianEdwards, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

private readonly ISystemClock _systemClock;
private readonly TimeSpan _timeWithoutRequestsUntilIdle;
private readonly TimeSpan _timerInterval;
private readonly uint _timerTicksWithoutRequestsUntilIdle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double? and _timerTicksSinceLastRequest can be double as well to avoid casting issues & equality check between int and uint. And equality check can become comparison (greater than) to avoid double precision issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeSpan? And increment by _timerInterval in the timer. (plus >= instead of ==)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but I did it a different way to what you suggested 😄

@DamianEdwards
Copy link
Member Author

Updated

@Tratcher
Copy link
Member

#223

@DamianEdwards DamianEdwards force-pushed the damianedwards/date-header-perf branch from d4e2d5a to 9b9d521 Compare September 24, 2015 23:56
@DamianEdwards
Copy link
Member Author

Rebased on #207

@AspNetSmurfLab
Copy link

With this change we see throughput go from ~244,000 RPS (with the changes in #207) to ~273,000 RPS. That's a nearly 12% increase in throughput.

@DamianEdwards DamianEdwards force-pushed the damianedwards/date-header-perf branch from 9b9d521 to 93bf994 Compare September 25, 2015 21:06
@DamianEdwards
Copy link
Member Author

ping @halter73 @lodejard @davidfowl

var now = _systemClock.UtcNow;

// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header
_dateValue = now.ToString("r");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move "r" to Constants class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really want me to do that? 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're not going to do that, at least move http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 to a resource string :trollface:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK doing that, it's actually kinda nice.

- Doing it on each request is expensive
- The Timer is started when the first request comes in and fires every second
- Every request flips a bool so the Timer knows requests are coming in
- The Timer stops itself after a period of no requests coming in (10 seconds)
- #163
@DamianEdwards DamianEdwards force-pushed the damianedwards/date-header-perf branch from 53643b6 to a7b65ef Compare September 25, 2015 22:00
@DamianEdwards
Copy link
Member Author

Updated again

@halter73
Copy link
Member

:shipit: assuming @lodejard is making the lifetime/dispose changes.

@DamianEdwards DamianEdwards merged commit a7b65ef into dev Sep 25, 2015
@davidfowl davidfowl deleted the damianedwards/date-header-perf branch March 19, 2017 08:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants