1
1
import logging
2
- import os
3
2
4
3
import uvicorn
4
+ from anyio import to_thread
5
5
from fastapi import FastAPI
6
6
from fastapi .middleware .cors import CORSMiddleware
7
7
@@ -122,6 +122,8 @@ def _add_middlewares(app):
122
122
def _init_fast_api ():
123
123
global_conf = config .get_global ()
124
124
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 )
125
127
126
128
return FastAPI (
127
129
title = global_conf .get ('REST_TITLE' , 'Document' ),
@@ -131,39 +133,7 @@ def _init_fast_api():
131
133
)
132
134
133
135
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
-
158
136
def 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
-
167
137
app = _init_fast_api ()
168
138
app = _add_middlewares (app )
169
139
app = _include_routers (app )
@@ -173,6 +143,12 @@ def fast_api_app():
173
143
def serve ():
174
144
conf = config .get_global ()
175
145
146
+ # Enable logging configuration\
147
+ set_logger ()
148
+
149
+ # Set OTel Tracer and Metric|
150
+ set_tracer ()
151
+
176
152
uvicorn_options = conf .get ('UVICORN_OPTIONS' , {})
177
153
178
154
_LOGGER .info (f'Start REST Server ({ config .get_service ()} ): '
0 commit comments