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

  • SEARCH
  • Home
  • 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 6219897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:51:52+00:00 2026-05-24T07:51:52+00:00

I’m using HttpListener as a simple http server. I’ve been benchmarking req/sec performance by

  • 0

I’m using HttpListener as a simple http server. I’ve been benchmarking req/sec performance by having HttpListener return the string “OK” to each request – this has hit a limit at 16,000 requests per second. Based on the following code, is there anything that I can do to further optimize performance? Or are we hitting the limits of Windows Http.sys?

Image uploading isn’t working, here’s a link to the Visual Studio performance trace:

VS Performance Trace

Public Class HTTPServer

    Shared Listener As HttpListener = New HttpListener

    Public Shared Sub Start()

        ServicePointManager.DefaultConnectionLimit = 500
        ServicePointManager.Expect100Continue = False
        ServicePointManager.MaxServicePoints = 500

        Listener.Prefixes.Add("http://localhost/")
        Listener.Start()

        For i As Integer = 1 To (System.Environment.ProcessorCount * 2)

            Dim NewThread As New System.Threading.Thread(AddressOf ListenerThread)
            NewThread.Priority = ThreadPriority.Normal
            NewThread.IsBackground = True
            NewThread.Start()

        Next

    End Sub



    Private Shared Sub ListenerThread()

        Dim SyncResult As IAsyncResult

        While True

            SyncResult = Listener.BeginGetContext(New AsyncCallback(AddressOf ListenerCallback), Listener)
            SyncResult.AsyncWaitHandle.WaitOne()

        End While

    End Sub



    Private Shared Sub ListenerCallback(ByVal StateObject As IAsyncResult)

        Dim Listener As HttpListener = DirectCast(StateObject.AsyncState, HttpListener)

        Dim Context As HttpListenerContext = Listener.EndGetContext(StateObject)
        Dim Request As HttpListenerRequest = Context.Request

        Dim Response As HttpListenerResponse = Context.Response

        Dim ResponseString As String = "OK"

        Dim Buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(ResponseString)
        Response.ContentLength64 = Buffer.Length
        Dim OutputStream As System.IO.Stream = Response.OutputStream
        OutputStream.Write(Buffer, 0, Buffer.Length)

        OutputStream.Close()
        OutputStream.Dispose()

    End Sub

End Class
  • 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-24T07:51:53+00:00Added an answer on May 24, 2026 at 7:51 am

    Well one thing you can do is only call Encoding.UTF8.GetBytes("OK") once, instead of on every request. I doubt that it’ll make much difference, but if you’re doing exactly the same thing on every request, you might as well have that response in the form you need it.

    I would also use a Using statement rather than calling Close and Dispose explicitly. That’s not a performance thing – just general good practice to avoid problems with unclosed streams when there are exceptions.

    Realistically, do you need to hit more than 16K QPS? Have you worked out whether you’re being CPU-bound or IO-bound? As soon as your program needs to actually do some real work on each request, I would imagine that will dwarf any micro-optimizations you make here anyway.

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

Sidebar

Related Questions

No related questions found

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.