Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router: Make the number of router threads configurable #1385

Merged
merged 1 commit into from
Aug 19, 2024

Commits on Aug 19, 2024

  1. router: Make the number of router threads configurable

    Unit generally creates an extra number of router threads (to handle
    client connections, not incl the main thread) to match the number of
    available CPUs.
    
    There are cases when this can go wrong, e.g on a high CPU count machine
    and Unit is being effectively limited to a few CPUs via the cgroups cpu
    controller. So Unit may create a large number of router threads when
    they are only going to effectively run on a couple of CPUs or so.
    
    There may be other cases where you would like to tweak the number of
    router threads, depending on your workload.
    
    As it turns out it looks like it was intended to be made configurable
    but was just never hooked up to the config system.
    
    This adds a new '/settings/listen_threads' config option which can be
    set like
    
      {
          "listen": {
              ...
          },
    
          "settings": {
              "listen_threads": 2,
    
              ...
          },
    
          ...
      }
    
    Before this patch (on a four cpu system)
    
      $  ps -efL | grep router
      andrew   419832 419829 419832  0    5 Aug12 pts/10   00:00:00 unit: router
      andrew   419832 419829 419833  0    5 Aug12 pts/10   00:00:00 unit: router
      andrew   419832 419829 419834  0    5 Aug12 pts/10   00:00:00 unit: router
      andrew   419832 419829 445145  0    5 03:31 pts/10   00:00:00 unit: router
      andrew   419832 419829 445146  0    5 03:31 pts/10   00:00:00 unit: router
    
    After, with a threads setting of 2
    
      $ ps -efL | grep router
      andrew   419832 419829 419832  0    3 Aug12 pts/10   00:00:00 unit: router
      andrew   419832 419829 419833  0    3 Aug12 pts/10   00:00:00 unit: router
      andrew   419832 419829 419834  0    3 Aug12 pts/10   00:00:00 unit: router
    
    Closes: nginx#1042
    Signed-off-by: Andrew Clayton <[email protected]>
    ac000 committed Aug 19, 2024
    Configuration menu
    Copy the full SHA
    57c88fd View commit details
    Browse the repository at this point in the history