Add logging of all round trips

I always log my http endpoints and my server calls with something like this:

@anvil.server.callable
def get_project(project_number, release_number):
    print(f'get_project({project_number}, {release_number})')

If the user opens a form or clicks on a button that requires updating both a label and a repeating panel, and each update makes server call, I see the two calls being logged and modify the logic so there is only one roundtrip to fetch both label and repeating panel content in one shot.

This helps me making sure I have only one roundtrip for every user interaction (when a form loads or when the user clicks somewhere).

I can see all my calls to the server because I log them, but unfortunately I don’t see the roundtrips caused by data table rows or iterators that lazily fetch some data.

I would like to see something like:

image

Here in orange the prints from the server, in blue the prints from the client and in green the prints from any roundtrip caused by any Anvil magic.

The app or the environment should have some setting that lists what needs to be logged.

This would help me keeping my apps lean and zippy, and the beginners understanding what’s going on under the hood.

8 Likes

BUMP.

I am working on an old app that has average response times above the 30 seconds.

The forms in the app keep calling server functions that return search iterators, then, on the client side, they build the content of repeating panels or other UI components.

The app was created by an ex colleague that didn’t follow the “never return a database row object to the form” rule that I love so much (rule number 2 here). He was happy to see the app working decently in a test environment, but after a few years the app became unusable.

If the app console had shown all the round trips, he would have done some optimization.

Now that I am refurbishing the app, in some cases I move the iterations to the server side, while in same cases I just add a q.fetch_only to ensure I get all the fields I need. I would love to have the round trips printed also now: sometimes the speed doesn’t improve, because I miss one column and the round trips keep happening anyway.

The first thing I did was to switch to accelerated tables. The result was that some functions were faster and some slower.

So far I have pushed the response times down from minutes to fractions of second in all the forms I have touched.

Had this FR been implemented, one of these two points would be true:

  • refurbishing the app now would be much easier
  • refurbishing the app now would be useless, because I would never be in this place
1 Like

Seconded. All of my server functions and background tasks have print statements like this, but I can’t do the same logging when it comes to search iterators sending server calls to fetch more data.

1 Like