Skip to content

Commit a803267

Browse files
barnabasdomozibruntib
authored andcommitted
Added flags to set server processes
Added --api-handler-processes and --task-worker-processes server flags. Using these flags overrides the corresponding values in the server config file.
1 parent 26a625d commit a803267

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

docs/web/user_guide.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ optional arguments:
186186
subsequent executions of the "same" server is achieved
187187
in distinct environments, e.g., if the server
188188
otherwise is running in a container.
189+
--api-handler-processes API_HANDLER_PROCESSES
190+
Number of API request handler processes the server should start.
191+
This setting overrides the server config file values.
192+
--task-worker-processes TASK_WORKER_PROCESSES
193+
Number of task worker processes the server should start.
194+
These handle report storage tasks (massStoreRun,
195+
massStoreRunAsynchronous).
196+
This setting overrides the server config file values.
189197
--host LISTEN_ADDRESS
190198
The IP address or hostname of the server on which it
191199
should listen for connections. For IPv6 listening,
@@ -256,6 +264,9 @@ By default, the running server can only be accessed from the same machine
256264
(`localhost`) where it is running. This can be overridden by specifying
257265
`--host ""`, instructing the server to listen on all available interfaces.
258266

267+
The server spawns additional Python processes to handle incoming API requests
268+
and to process report storing tasks. The process counts can be changed using
269+
the `--api-handler-processes` and `--task-worker-processes` flags, respectively.
259270

260271
#### Run CodeChecker server in Docker
261272
To run CodeChecker server in Docker see the [Docker](docker.md) documentation.
@@ -1796,4 +1807,4 @@ In JSON output we have two main sections:
17961807
17971808
## Log Levels
17981809
1799-
To change the log levels check out the [logging](../logging.md) documentation.
1810+
To change the log levels check out the [logging](../logging.md) documentation.

web/server/codechecker_server/api/report_server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
SourceComponentData, SourceFileData, SortMode, SortType, \
4949
SubmittedRunOptions
5050

51+
from codechecker_api_shared.ttypes import ErrorCode, RequestFailed
52+
5153
from codechecker_common import util
5254
from codechecker_common.logger import get_logger
5355

@@ -3999,6 +4001,10 @@ def __massStoreRun_common(self, is_async: bool, zipfile_blob: str,
39994001
if not store_opts.runName:
40004002
raise ValueError("A run name is needed to know where to store!")
40014003

4004+
if self._manager.background_worker_processes == 0:
4005+
raise RequestFailed(ErrorCode.GENERAL,
4006+
"No task worker process is available!")
4007+
40024008
from .mass_store_run import MassStoreRunInputHandler, MassStoreRunTask
40034009
ih = MassStoreRunInputHandler(self._manager,
40044010
self._config_database,

web/server/codechecker_server/cli/server.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,25 @@ def add_arguments_to_parser(parser):
113113
In most scenarios, there is no need to fine-tune this, except if subsequent
114114
executions of the "same" server is achieved in distinct environments, e.g.,
115115
if the server otherwise is running in a container.
116+
""")
117+
118+
parser.add_argument("--api-handler-processes",
119+
type=int,
120+
dest="api_handler_processes",
121+
required=False,
122+
help="""
123+
Number of API request handler processes the server should start.
124+
This setting overrides the server config file values.
125+
""")
126+
127+
parser.add_argument("--task-worker-processes",
128+
type=int,
129+
dest="task_worker_processes",
130+
required=False,
131+
help="""
132+
Number of task worker processes the server should start.
133+
These handle report storage tasks (massStoreRun, massStoreRunAsynchronous).
134+
This setting overrides the server config file values.
116135
""")
117136

118137
parser.add_argument('--host',
@@ -1043,7 +1062,9 @@ def server_init_start(args):
10431062
args.skip_db_cleanup,
10441063
context,
10451064
environ,
1046-
machine_id)
1065+
machine_id,
1066+
args.api_handler_processes,
1067+
args.task_worker_processes)
10471068
except socket.error as err:
10481069
if err.errno == errno.EADDRINUSE:
10491070
LOG.error("Server can't be started, maybe port number (%s) is "

web/server/codechecker_server/server.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,9 @@ def start_server(config_directory: str, workspace_directory: str,
992992
package_data, port: int, config_sql_server,
993993
listen_address: str, force_auth: bool,
994994
skip_db_cleanup: bool, context, check_env,
995-
machine_id: str) -> int:
995+
machine_id: str,
996+
api_handler_processes: Optional[int],
997+
task_worker_processes: Optional[int]) -> int:
996998
"""
997999
Starts the HTTP server to handle Web client and Thrift requests, execute
9981000
background jobs.
@@ -1036,7 +1038,9 @@ def start_server(config_directory: str, workspace_directory: str,
10361038
manager = session_manager.SessionManager(
10371039
server_cfg_file,
10381040
server_secrets_file,
1039-
force_auth)
1041+
force_auth,
1042+
api_handler_processes,
1043+
task_worker_processes)
10401044

10411045
except IOError as ioerr:
10421046
LOG.debug(ioerr)
@@ -1067,8 +1071,7 @@ def start_server(config_directory: str, workspace_directory: str,
10671071

10681072
bg_processes: Dict[int, Process] = {}
10691073
requested_bg_threads = cast(int,
1070-
manager.background_worker_processes) \
1071-
or requested_api_threads
1074+
manager.background_worker_processes)
10721075
# Note that Queue under the hood uses OS-level primitives such as a socket
10731076
# or a pipe, where the read-write buffers have a **LIMITED** capacity, and
10741077
# are usually **NOT** backed by the full amount of available system memory.
@@ -1220,7 +1223,7 @@ def spawn_bg_process():
12201223
signal_log(LOG, "DEBUG", f"Task child process {p.pid} started!")
12211224
return p
12221225

1223-
LOG.info("Using %d Task handler processes ...", requested_bg_threads)
1226+
LOG.info("Using %d Task worker processes ...", requested_bg_threads)
12241227
for _ in range(requested_bg_threads):
12251228
spawn_bg_process()
12261229

web/server/codechecker_server/session_manager.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ class SessionManager:
171171
CodeChecker server.
172172
"""
173173

174-
def __init__(self, configuration_file, secrets_file, force_auth=False):
174+
def __init__(self, configuration_file, secrets_file, force_auth=False,
175+
api_handler_processes: Optional[int] = None,
176+
task_worker_processes: Optional[int] = None):
175177
"""
176178
Initialise a new Session Manager on the server.
177179
@@ -194,6 +196,13 @@ def __init__(self, configuration_file, secrets_file, force_auth=False):
194196
# instantiate SessionManager with the found configuration.
195197
self.__worker_processes, self.__background_worker_processes = \
196198
get_worker_processes(self.scfg_dict)
199+
200+
if api_handler_processes is not None:
201+
self.__worker_processes = api_handler_processes
202+
203+
if task_worker_processes is not None:
204+
self.__background_worker_processes = task_worker_processes
205+
197206
self.__max_run_count = self.scfg_dict.get('max_run_count', None)
198207
self.__store_config = self.scfg_dict.get('store', {})
199208
self.__keepalive_config = self.scfg_dict.get('keepalive', {})

0 commit comments

Comments
 (0)