11import logging
2- import os
32
43import uvicorn
4+ from anyio import to_thread
55from fastapi import FastAPI
66from fastapi .middleware .cors import CORSMiddleware
77
@@ -122,6 +122,8 @@ def _add_middlewares(app):
122122def _init_fast_api ():
123123 global_conf = config .get_global ()
124124 server_info = ServerInfoManager ()
125+ # set thread pool size
126+ to_thread .current_default_thread_limiter ().total_tokens = global_conf .get ('REST_MAX_THREAD_POOL' , 40 )
125127
126128 return FastAPI (
127129 title = global_conf .get ('REST_TITLE' , 'Document' ),
@@ -131,39 +133,7 @@ def _init_fast_api():
131133 )
132134
133135
134- def set_server_config_from_env ():
135- package = os .environ .get ('SPACEONE_PACKAGE' )
136- host = os .environ ['SPACEONE_HOST' ]
137- module_path = tuple (os .environ .get ('SPACEONE_MODULE_PATH' ).split (', ' ))
138- port = os .environ .get ('SPACEON_PORT' )
139- config_file = os .environ .get ('SPACEONE_CONFIG_FILE' )
140-
141- # 1. Set a python path
142- utils .set_python_path (package , module_path )
143-
144- # 2. Initialize config from command argument
145- config .init_conf (
146- package = package ,
147- port = port
148- )
149-
150- # 3. Get service config from global_conf.py
151- config .set_service_config ()
152-
153- # 4. Merge file conf
154- if config_file :
155- config .set_file_conf (config_file )
156-
157-
158136def fast_api_app ():
159- set_server_config_from_env ()
160-
161- # Enable logging configuration\
162- set_logger ()
163-
164- # Set OTel Tracer and Metric|
165- set_tracer ()
166-
167137 app = _init_fast_api ()
168138 app = _add_middlewares (app )
169139 app = _include_routers (app )
@@ -173,6 +143,12 @@ def fast_api_app():
173143def serve ():
174144 conf = config .get_global ()
175145
146+ # Enable logging configuration\
147+ set_logger ()
148+
149+ # Set OTel Tracer and Metric|
150+ set_tracer ()
151+
176152 uvicorn_options = conf .get ('UVICORN_OPTIONS' , {})
177153
178154 _LOGGER .info (f'Start REST Server ({ config .get_service ()} ): '
0 commit comments