Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6163173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:46:49+00:00 2026-05-23T21:46:49+00:00

Background I have an implementation of an HTTP server in C#. Using ab I

  • 0

Background

I have an implementation of an HTTP server in C#.
Using ab I discovered a weird performance issue.
Each request took 5 ms with Keep-Alive Off but 40 ms with Keep-Alive on!

The testpage is generated into a single byte[] which get sent as reply using a single socket.Send call.

The cause is as far as I can tell Nagle’s algorithm used in the TCP stack.

TCP Flush?

So far I am using the NoDelay property in the end of every HTTP request served.

socket.NoDelay = true;
socket.NoDelay = false;

Which does solve the problem for now. But I have no documentation to backup my discovery.

This was tested on a linux/mono system.

Is there a standard way of flushing the TCP connection?

Related

This answer is addressing the same issue. The difference here is that I am looking to only temporarily disabling the algorithm.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:46:49+00:00Added an answer on May 23, 2026 at 9:46 pm

    I tested this with Wireshark. Unfortunately,

    socket.NoDelay = true;
    socket.NoDelay = false;
    

    has no effect. Similarly,

    socket.NoDelay = true;
    socket.Send(new byte[0]);
    socket.NoDelay = false;
    

    also has no effect. From observed behaviour, it appears that the NoDelay property only affects the next call to Send with a non-empty buffer. In other words, you have to send some actual data before NoDelay will have any effect.

    Therefore, I conclude that there is no way to explicitly flush the socket if you don’t want to send any extra data.

    However, since you are writing an HTTP server, you may be able to use a few tricks:

    • For requests that are served using Transfer-Encoding: chunked, you can send the end-of-stream marker (the "\r\n0\r\n\r\n") with NoDelay = true.
    • If you are serving a file from the local filesystem, you will know when the file ends, so you could set NoDelay = true just before sending the last chunk.
    • For requests that are served using Content-Encoding: gzip, you can set NoDelay = true just before closing the gzip stream; the gzip stream will send some last bits before actually finishing and closing.

    I’m certainly going to add the above to my HTTP server now 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background Fluent NHibernate 1.1 (with a repository implementation using LINQ to NHibernate) in an
Background I have written very simple BBCode parser using C# which transforms BBCode to
I want my InfoWindows in my Google Map implementation to have a black background
I have a HTTP Live streaming server setup that serves segmented mp3 audio content
I have already added delay loading to my project, using the instructions in http://msdn.microsoft.com/en-us/library/151kt790.aspx
I have UINavigationBar subclassed and I add a custom background like so: @implementation CustomUINavigationBar
Background: I have a little video playing app with a UI inspired by the
Background I have a massive db for a SharePoint site collection. It is 130GB
Background I have been asked by a client to create a picture of the
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.