Skip to content

Commit e6217a9

Browse files
committed
Use uwsgi for glance-api
This commit adds support for deploying glance as a wsgi script under uwsgi. To get around limitations in the uwsgi protocol when using python3 for chunked encoding we have to setup uwsgi in http mode on a random port listening on localhost and use mod_proxy to forward the incoming requests. The alternative approach of having apache buffer the requests locally with the send_cl option with mod_proxy_uwsgi only worked on python2 and also has the limitation that apache is buffering the entire chunked object, which could be several gigabytes in size. Depends-On: I089a22a4be4227a551c32442dba27c426f54c87d Change-Id: Ie98fb7da5e8ecfa49cd680b88139cb7034d5f88f
1 parent 309b99e commit e6217a9

4 files changed

Lines changed: 83 additions & 14 deletions

File tree

lib/apache

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,64 @@ function write_uwsgi_config {
260260
else
261261
local apache_conf=""
262262
apache_conf=$(apache_site_config_for $name)
263-
echo "ProxyPass \"${url}\" \"unix:${socket}|uwsgi://uwsgi-uds-${name}/\" retry=0 " | sudo tee $apache_conf
263+
echo "SetEnv proxy-sendcl 1" | sudo tee $apache_conf
264+
echo "ProxyPass \"${url}\" \"unix:${socket}|uwsgi://uwsgi-uds-${name}/\" retry=0 " | sudo tee -a $apache_conf
264265
enable_apache_site $name
265266
restart_apache_server
266267
fi
267268
}
268269

270+
# For services using chunked encoding, the only services known to use this
271+
# currently are Glance and Swift, we need to use an http proxy instead of
272+
# mod_proxy_uwsgi because the chunked encoding gets dropped. See:
273+
# https://github.com/unbit/uwsgi/issues/1540 You can workaround this on python2
274+
# but that involves having apache buffer the request before sending it to
275+
# uswgi.
276+
function write_local_uwsgi_http_config {
277+
local file=$1
278+
local wsgi=$2
279+
local url=$3
280+
name=$(basename $wsgi)
281+
282+
# create a home for the sockets; note don't use /tmp -- apache has
283+
# a private view of it on some platforms.
284+
285+
# always cleanup given that we are using iniset here
286+
rm -rf $file
287+
iniset "$file" uwsgi wsgi-file "$wsgi"
288+
port=$(get_random_port)
289+
iniset "$file" uwsgi http "127.0.0.1:$port"
290+
iniset "$file" uwsgi processes $API_WORKERS
291+
# This is running standalone
292+
iniset "$file" uwsgi master true
293+
# Set die-on-term & exit-on-reload so that uwsgi shuts down
294+
iniset "$file" uwsgi die-on-term true
295+
iniset "$file" uwsgi exit-on-reload true
296+
iniset "$file" uwsgi enable-threads true
297+
iniset "$file" uwsgi plugins python
298+
# uwsgi recommends this to prevent thundering herd on accept.
299+
iniset "$file" uwsgi thunder-lock true
300+
# Override the default size for headers from the 4k default.
301+
iniset "$file" uwsgi buffer-size 65535
302+
# Make sure the client doesn't try to re-use the connection.
303+
iniset "$file" uwsgi add-header "Connection: close"
304+
# This ensures that file descriptors aren't shared between processes.
305+
iniset "$file" uwsgi lazy-apps true
306+
iniset "$file" uwsgi chmod-socket 666
307+
iniset "$file" uwsgi http-raw-body true
308+
iniset "$file" uwsgi http-chunked-input true
309+
iniset "$file" uwsgi http-auto-chunked true
310+
311+
enable_apache_mod proxy
312+
enable_apache_mod proxy_http
313+
local apache_conf=""
314+
apache_conf=$(apache_site_config_for $name)
315+
echo "KeepAlive Off" | sudo tee $apache_conf
316+
echo "ProxyPass \"${url}\" \"http://127.0.0.1:$port\" retry=0 " | sudo tee -a $apache_conf
317+
enable_apache_site $name
318+
restart_apache_server
319+
}
320+
269321
function remove_uwsgi_config {
270322
local file=$1
271323
local wsgi=$2

lib/cinder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function configure_cinder {
347347

348348
iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
349349

350-
iniset $CINDER_CONF DEFAULT glance_api_servers "${GLANCE_SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}"
350+
iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
351351
if is_service_enabled tls-proxy; then
352352
iniset $CINDER_CONF DEFAULT glance_protocol https
353353
iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE

lib/glance

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$GLANCE_SERVICE_HOST:$GLANCE_SERVICE_PORT}
7171
GLANCE_SERVICE_PROTOCOL=${GLANCE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
7272
GLANCE_REGISTRY_PORT=${GLANCE_REGISTRY_PORT:-9191}
7373
GLANCE_REGISTRY_PORT_INT=${GLANCE_REGISTRY_PORT_INT:-19191}
74+
GLANCE_UWSGI=$GLANCE_BIN_DIR/glance-wsgi-api
75+
GLANCE_UWSGI_CONF=$GLANCE_CONF_DIR/glance-uswgi.ini
76+
# If wsgi mode is uwsgi run glance under uwsgi, else default to eventlet
77+
# TODO(mtreinish): Remove the eventlet path here and in all the similar
78+
# conditionals below after the Pike release
79+
if [[ "$WSGI_MODE" == "uwsgi" ]]; then
80+
GLANCE_URL="$GLANCE_SERVICE_PROTOCOL://$GLANCE_SERVICE_HOST/image"
81+
else
82+
GLANCE_URL="$GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT"
83+
fi
7484

7585
# Functions
7686
# ---------
@@ -103,16 +113,13 @@ function configure_glance {
103113
dburl=`database_connection_url glance`
104114
iniset $GLANCE_REGISTRY_CONF database connection $dburl
105115
iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
106-
iniset $GLANCE_REGISTRY_CONF DEFAULT workers "$API_WORKERS"
107116
iniset $GLANCE_REGISTRY_CONF paste_deploy flavor keystone
108117
configure_auth_token_middleware $GLANCE_REGISTRY_CONF glance $GLANCE_AUTH_CACHE_DIR/registry
109118
iniset $GLANCE_REGISTRY_CONF oslo_messaging_notifications driver messagingv2
110119
iniset_rpc_backend glance $GLANCE_REGISTRY_CONF
111120
iniset $GLANCE_REGISTRY_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
112121

113-
cp $GLANCE_DIR/etc/glance-api.conf $GLANCE_API_CONF
114122
iniset $GLANCE_API_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
115-
iniset $GLANCE_API_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
116123
inicomment $GLANCE_API_CONF DEFAULT log_file
117124
iniset $GLANCE_API_CONF database connection $dburl
118125
iniset $GLANCE_API_CONF DEFAULT use_syslog $SYSLOG
@@ -140,8 +147,6 @@ function configure_glance {
140147
iniset $GLANCE_API_CONF glance_store filesystem_store_datadir $GLANCE_IMAGE_DIR/
141148
iniset $GLANCE_API_CONF DEFAULT registry_host $GLANCE_SERVICE_HOST
142149

143-
iniset $GLANCE_API_CONF DEFAULT workers "$API_WORKERS"
144-
145150
# CORS feature support - to allow calls from Horizon by default
146151
if [ -n "$GLANCE_CORS_ALLOWED_ORIGIN" ]; then
147152
iniset $GLANCE_API_CONF cors allowed_origin "$GLANCE_CORS_ALLOWED_ORIGIN"
@@ -198,7 +203,6 @@ function configure_glance {
198203
setup_logging $GLANCE_REGISTRY_CONF
199204

200205
cp -p $GLANCE_DIR/etc/glance-registry-paste.ini $GLANCE_REGISTRY_PASTE_INI
201-
202206
cp -p $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
203207

204208
cp $GLANCE_DIR/etc/glance-cache.conf $GLANCE_CACHE_CONF
@@ -231,6 +235,13 @@ function configure_glance {
231235
iniset $GLANCE_API_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/%(project_id)s"
232236
iniset $GLANCE_CACHE_CONF DEFAULT cinder_endpoint_template "https://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/%(project_id)s"
233237
fi
238+
239+
if [[ "$WSGI_MODE" == "uwsgi" ]]; then
240+
write_local_uwsgi_http_config "$GLANCE_UWSGI_CONF" "$GLANCE_UWSGI" "/image"
241+
else
242+
iniset $GLANCE_API_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
243+
iniset $GLANCE_API_CONF DEFAULT workers "$API_WORKERS"
244+
fi
234245
}
235246

236247
# create_glance_accounts() - Set up common required glance accounts
@@ -255,7 +266,7 @@ function create_glance_accounts {
255266
get_or_create_endpoint \
256267
"image" \
257268
"$REGION_NAME" \
258-
"$GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT"
269+
"$GLANCE_URL"
259270

260271
# Note(frickler): Crude workaround for https://bugs.launchpad.net/glance-store/+bug/1620999
261272
service_domain_id=$(get_or_create_domain $SERVICE_DOMAIN_NAME)
@@ -320,15 +331,21 @@ function install_glance {
320331
function start_glance {
321332
local service_protocol=$GLANCE_SERVICE_PROTOCOL
322333
if is_service_enabled tls-proxy; then
323-
start_tls_proxy glance-service '*' $GLANCE_SERVICE_PORT $GLANCE_SERVICE_HOST $GLANCE_SERVICE_PORT_INT
334+
if [[ "$WSGI_MODE" != "uwsgi" ]]; then
335+
start_tls_proxy glance-service '*' $GLANCE_SERVICE_PORT $GLANCE_SERVICE_HOST $GLANCE_SERVICE_PORT_INT
336+
fi
324337
start_tls_proxy glance-registry '*' $GLANCE_REGISTRY_PORT $GLANCE_SERVICE_HOST $GLANCE_REGISTRY_PORT_INT
325338
fi
326339

327340
run_process g-reg "$GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
328-
run_process g-api "$GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
341+
if [[ "$WSGI_MODE" == "uwsgi" ]]; then
342+
run_process g-api "$GLANCE_BIN_DIR/uwsgi --ini $GLANCE_UWSGI_CONF"
343+
else
344+
run_process g-api "$GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
345+
fi
329346

330-
echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
331-
if ! wait_for_service $SERVICE_TIMEOUT $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT; then
347+
echo "Waiting for g-api ($GLANCE_SERVICE_HOST) to start..."
348+
if ! wait_for_service $SERVICE_TIMEOUT $GLANCE_URL; then
332349
die $LINENO "g-api did not start"
333350
fi
334351
}

lib/nova

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ function create_nova_conf {
574574
# enable notifications, but it will allow them to function when enabled.
575575
iniset $NOVA_CONF oslo_messaging_notifications driver "messagingv2"
576576
iniset_rpc_backend nova $NOVA_CONF
577-
iniset $NOVA_CONF glance api_servers "${GLANCE_SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}"
577+
iniset $NOVA_CONF glance api_servers "$GLANCE_URL"
578578

579579
iniset $NOVA_CONF DEFAULT osapi_compute_workers "$API_WORKERS"
580580
iniset $NOVA_CONF DEFAULT metadata_workers "$API_WORKERS"

0 commit comments

Comments
 (0)