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 110205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:11:25+00:00 2026-05-11T02:11:25+00:00

I am writing a server, and I send each action of into a separate

  • 0

I am writing a server, and I send each action of into a separate thread when the request is received. I do this because almost every request makes a database query. I am using a threadpool library to cut down on construction/destruction of threads.

My question is: what is a good cutoff point for I/O threads like these? I know it would just be a rough estimate, but are we talking hundreds? Thousands?

How would I go about figuring out what this cutoff would be?


EDIT:

Thank you all for your responses, it seems like I am just going to have to test it to find out my thread count ceiling. The question is though: how do I know I’ve hit that ceiling? What exactly should I measure?

  • 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. 2026-05-11T02:11:26+00:00Added an answer on May 11, 2026 at 2:11 am

    Some people would say that two threads is too many – I’m not quite in that camp 🙂

    Here’s my advice: measure, don’t guess. One suggestion is to make it configurable and initially set it to 100, then release your software to the wild and monitor what happens.

    If your thread usage peaks at 3, then 100 is too much. If it remains at 100 for most of the day, bump it up to 200 and see what happens.

    You could actually have your code itself monitor usage and adjust the configuration for the next time it starts but that’s probably overkill.


    For clarification and elaboration:

    I’m not advocating rolling your own thread pooling subsystem, by all means use the one you have. But, since you were asking about a good cut-off point for threads, I assume your thread pool implementation has the ability to limit the maximum number of threads created (which is a good thing).

    I’ve written thread and database connection pooling code and they have the following features (which I believe are essential for performance):

    • a minimum number of active threads.
    • a maximum number of threads.
    • shutting down threads that haven’t been used for a while.

    The first sets a baseline for minimum performance in terms of the thread pool client (this number of threads is always available for use). The second sets a restriction on resource usage by active threads. The third returns you to the baseline in quiet times so as to minimise resource use.

    You need to balance the resource usage of having unused threads (A) against the resource usage of not having enough threads to do the work (B).

    (A) is generally memory usage (stacks and so on) since a thread doing no work will not be using much of the CPU. (B) will generally be a delay in the processing of requests as they arrive as you need to wait for a thread to become available.

    That’s why you measure. As you state, the vast majority of your threads will be waiting for a response from the database so they won’t be running. There are two factors that affect how many threads you should allow for.

    The first is the number of DB connections available. This may be a hard limit unless you can increase it at the DBMS – I’m going to assume your DBMS can take an unlimited number of connections in this case (although you should ideally be measuring that as well).

    Then, the number of threads you should have depend on your historical use. The minimum you should have running is the minimum number that you’ve ever had running + A%, with an absolute minimum of (for example, and make it configurable just like A) 5.

    The maximum number of threads should be your historical maximum + B%.

    You should also be monitoring for behaviour changes. If, for some reason, your usage goes to 100% of available for a significant time (so that it would affect the performance of clients), you should bump up the maximum allowed until it’s once again B% higher.


    In response to the ‘what exactly should I measure?’ question:

    What you should measure specifically is the maximum amount of threads in concurrent use (e.g., waiting on a return from the DB call) under load. Then add a safety factor of 10% for example (emphasised, since other posters seem to take my examples as fixed recommendations).

    In addition, this should be done in the production environment for tuning. It’s okay to get an estimate beforehand but you never know what production will throw your way (which is why all these things should be configurable at runtime). This is to catch a situation such as unexpected doubling of the client calls coming in.

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

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can try something like this. Suppose you have this… May 11, 2026 at 3:21 pm
  • added an answer Splitting the label text into text and number part using… May 11, 2026 at 3:20 pm
  • added an answer While not specifically an app you can download, Developing a… May 11, 2026 at 3:20 pm

Related Questions

I am writing a controller for an audio server on the iPhone. Each 'view'
I was hoping to implement a simple XMPP server in Java. What I need
Leading on from my previous questions I am going to try and clarify one
At the company I work for, I have created a Error Logging class to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.