I have a problem where the Anvil app is very sluggish (since last Saturday or so).
From the looks of it, the call from the frontend form to the server module is taking a long time.
Here are the timestamps when the frontend module called the server module:
12:34:00.673300 (frontend calls server module)
12:34:10.762420 (server module receives the call)
Any ideas why this would take 10 seconds?
Hi Anders,
That’s strange! I’ve just tested with a simple app and it seems to be responding fine. Do you have an app that’s experiencing this problem right now, which I can clone? (Feel free to PM the clone link to me if you don’t want to share it on an open forum.)
One possibility… Are you measuring the time til your code starts running, or the time til the function call? By default, Anvil reloads your server modules for each call, so if you’re doing something slow in the initialisation of your server modules, that will have to execute before your server module runs. Eg if your server module looks like this:
import anvil.server
x = DO_SOMETHING_SLOW()
@anvil.server.callable
def foo():
return something_else()
…then the DO_SOMETHING_SLOW()
call will execute every time you make a server call.
(Of course, if it’s suddenly slowed down since Saturday, that’s still a new problem, but if it’s a new problem in your module initialisation that will still help us track it down…)
Thanks for quick response.
It actually looks like the import requests
library at the start of server module is the action that takes a long time.
That’s…bizarre! I’ve just tested with import requests
in a blank sample app, and that’s going at a normal speed for me.
Weird…
I have this in the server module now:
`from datetime import datetime
print(“datetime imported:”)
print(datetime.now().time())
import tables
print(“tables imported:”)
print(datetime.now().time())
from tables import app_tables
import anvil.users
print(“anvil users imported:”)
print(datetime.now().time())
import anvil.server
print(“anvil.server imported:”)
print(datetime.now().time())
import requests
print(“requests imported:”)
print(datetime.now().time())
import certifi
print(“certifi imported:”)
print(datetime.now().time())
import json
print(“json imported:”)
print(datetime.now().time())
import time
print(“time imported:”)
print(datetime.now().time())
from dateutil import parser
print(“dateutil parser imported:”)
print(datetime.now().time())
import pytz
print(“pytz imported:”)
print(datetime.now().time())
print(“server module fully initialized:”)
print(datetime.now().time())`
And it produces these timestamps:
datetime imported: 11:51:55.161743 tables imported: 11:51:55.162220 anvil users imported: 11:51:55.162908 anvil.server imported: 11:51:55.162941 requests imported: 11:52:01.263498 certifi imported: 11:52:01.263541 json imported: 11:52:01.263569 time imported: 11:52:01.263594 dateutil parser imported: 11:52:01.461336 pytz imported: 11:52:01.464414 server module fully initialized: 11:52:01.464451
@anders.kalland and I are corresponding privately. Short answer is that he’s been exhausting his CPU quota with an uplink-driven background task!