LCOV - code coverage report
Current view: top level - server/config - ThreadSettingsConfig.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 12 12 100.0 %
Date: 2022-11-19 15:00:39 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2015 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.config;
      16             : 
      17             : import com.google.inject.Inject;
      18             : import com.google.inject.Singleton;
      19             : import org.eclipse.jgit.lib.Config;
      20             : 
      21             : @Singleton
      22             : public class ThreadSettingsConfig {
      23             :   private final int sshdThreads;
      24             :   private final int httpdMaxThreads;
      25             :   private final int sshdBatchThreads;
      26             :   private final int databasePoolLimit;
      27             : 
      28             :   @Inject
      29         138 :   ThreadSettingsConfig(@GerritServerConfig Config cfg) {
      30         138 :     int cores = Runtime.getRuntime().availableProcessors();
      31         138 :     sshdThreads = cfg.getInt("sshd", "threads", Math.max(4, 2 * cores));
      32         138 :     httpdMaxThreads = cfg.getInt("httpd", "maxThreads", 25);
      33         138 :     int defaultDatabasePoolLimit = sshdThreads + httpdMaxThreads + 2;
      34         138 :     databasePoolLimit = cfg.getInt("database", "poolLimit", defaultDatabasePoolLimit);
      35         138 :     sshdBatchThreads = cores == 1 ? 1 : 2;
      36         138 :   }
      37             : 
      38             :   public int getDatabasePoolLimit() {
      39         138 :     return databasePoolLimit;
      40             :   }
      41             : 
      42             :   public int getHttpdMaxThreads() {
      43          99 :     return httpdMaxThreads;
      44             :   }
      45             : 
      46             :   public int getSshdThreads() {
      47          17 :     return sshdThreads;
      48             :   }
      49             : 
      50             :   public int getSshdBatchTreads() {
      51          17 :     return sshdBatchThreads;
      52             :   }
      53             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750