The following global imports seem to increase the initialization latency from 4s to ~ 50s:
from keras.optimizers import Adam
from keras.models import load_model
This only occurs on the live app engine and not the development preview, which runs main.py almost instantaneously.
I'm on keras==2.2.4
and tensorflow==1.14.0
. I checked the logs and the error reporting, and there don't seem to be any errors.
One thing I noticed is in the logs it prints out Using Tensorflow Backend
about 8 times, whereas the development preview only says it once. Is it re-importing keras on loop?
I am running on Flask==1.1.2
and instance class F4_1G
.
There's also a 30 second delay between tensorflow setup processes?
Edit #1:
The logs still show multiple Using Tensorflow Backend
despite only intializing a single instance. Also, I'm not sure why the memory is at 1.1GB. I don't initialize anything globally besides a few strings.
Edit #2:
Using Tensorflow Backend
is printed out 8 times because there are 8 gunicorn
workers, I think. I can reduce the workers by scaling back my instance type to one smaller than F4_1G
, but then the logs show that I've Exceeded soft memory limit
and that I should upgrade my instance type. Not sure why the initialization takes so much memory (1.1 GB).