Understanding http endpoints: latency, threading, async

I have made an http endpoint that process a request, involving the creation of a pandas dataframe (different for different users), and return some result to the user. No changes to database tables is involved, so that is not a problem.

I have read the documentation which was very helpful, but I still started to worry and optimize (both!), and wanted to ask those who know more than me about the nature of http endpoints:

  • First, basic question, but I want to make sure: When multiple clients send concurrent requests to the endpoint, my understanding is that they get a clean sheet every time? For instance, the dataframe created in one call does not pollute the other even if they have the same name.

  • I also assume an endpoint does not block while processing a request? (If so, using asyncio would help - but this might create problems with different dataframes having the same name?)

  • Lastly, right now the first request to the endpoint takes a little bit of time. How much less would it be if the server was permanent (Business plan)? I know it would depend on the size/number of packages we import, but maybe users have some experiences they could share?

(And I assume each http call still get a clean sheet with a permanent server, only that now the packages are preloaded? (No namespace problems (good), but also no caching opportunities?)

This is true, unless your plan allows the persistent server option and you do enable it (you should), and your store your dataframe in a global variable.

This is great, because it allows you to store read only global values and rely on them if you are lucky, or local values in the function scope.

Correct.

The persistent server option would eliminate the time required for the import. You would only have network and execution time.

Very good. Thank you!

Seems like a good idea to use persistent servers not only to reduce time spent importing modules, but maybe more importantly in my case: to use global variables for caching to avoid reloading dataframes/recomputing results (many of my calls are identical). And threading on the server side seems to be an unnecessary complication in my case.

Anvil endpoints are really great. An easy way to create very powerful things!

2 Likes