Thank you for your reply, Dave. If I understand you correctly, I already did what you suggested: move those imports into a module file. It did not help.
Today I found web2py profiler and use the profiler I confirmed the scheduler is indeed the bottleneck. And indeed imports is the problem, especially the slow "plotly" module. So I moved that import into the function where plot.ly is used, then problem sovled. As confirmed here, *import inside a function will not be imported unless the function is called.* https://stackoverflow.com/questions/3095071/in-python-what-happens-when-you-import-inside-of-a-function I am not sure this is unique tip to web2py. Hope my experience will be helpful to others. On Sunday, February 3, 2019 at 1:17:48 PM UTC-8, Dave S wrote: > > > > On Saturday, February 2, 2019 at 3:48:43 PM UTC-8, Yi Liu wrote: >> >> Dear fellow users, >> >> I have an app with a scheduler, it uses these modules: >> >> import nunumpy as np >> import pandas as pd >> pd.core.common.is_list_like = pd.api.types.is_list_like >> import pandas_datareader as web >> import requests >> import datetime >> from tenacity import retry, stop, wait >> import time, os >> import sys >> import traceback >> import plotly.plotly as py >> from gluon import * >> >> I used to put them along with about a dozen functions directly in >> scheduler.py. Later I learned that I should not put code in models since it >> will make the app slow. It is indeed slower than other apps on the same >> server. >> >> So I moved them into a module file, which is imported at the beginning of >> scheduler.py >> >> But still the page take 7 sec to load, subsequent actions are much >> faster once loaded. I compile the app and enabled lazy_tables >> >> > Importing into scheduler.py is probably not an improvement over having the > modules in the models directory; scheduler.py is run on every request > because it is a model. Instead, import just the code directly called from > scheduler.py (for me, a module called upwatcher.py) > >> My question is:, and have that module import the rest. >> > > > >> >> Are these imports slowing down my app ? Despite that I moved them into a >> module? >> >> Is there a way to speed up this process? 7 secs is too slow. >> >> My index controller function is pretty simple. Is there any other thing I >> should optimize? >> >> My app in question: gapdb.com >> My comparing app : trialert.com >> >> Thank you for any help. >> >> Yi >> >> /dps >> > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

