Latency issues in a very simple server call

I noticed that my very simple server calls (e.g. just return an int) had really high latency, like 2-3 seconds. I’m trying to find out why and get that down to an acceptable level. I’ve probably read all forum posts concerning latency and server optimization but I’m really just trying to call a function like this:

@anvil.server.callable
def get_int():
  return 7

The only imports in my server module are

from anvil.tables import app_tables
import anvil.server

I call this from the client like this:

def button_1_click(self, **event_args):
    """This method is called when the button is clicked"""
    start = datetime.datetime.now()
    number = anvil.server.call_s('get_int')      
    print('got number', number, datetime.datetime.now() - start)

My app is making no other server calls and has no background tasks. When I run this app, the call usually takes between 1.5 and 2 seconds, which is obviously very slow. Interestingly, when I created a new app, and copy-pasted the exact same code on both client and server side, it works much faster, with timings around 0.3 seconds.

What could explain the difference in the latency while running the exact same code on two different apps?

If you clone the slow app, do you get another slow app?

1 Like

Cloned app behaves similarly to the original. Trying now, without changing anything, the app works faster with the average timing around 0.7s, while the simple test app still performs very consistently around 0.3s. If it stays under a second it’s workable but it’s still double the time for no apparent reason. What sort of latency is expected for such a simple call? I’m in Europe so 0.7s still sounds pretty high.

If you don’t have persistent server enabled (available on dedicated plans only if I remember correctly), then the server loads the whole app every time it receives a call.

Try to clone both fast and slow app to your computer, then compare the git repositories and see if there is something large, like an image on a form, that is slowing it down.

I figured out what was different. It was the python version on the server. Changing it to Full Python 3 now gives me the same latency. The other options seem to at least double the latency.

1 Like