Multiple instances of app

How many instances (processes) of the app is expected to run on cloud? I’d expect it to be one, but directly get four.

  1. Create new web project
  2. Do nothing more than select server and domain name in build settings → Xojo Cloud
  3. Deploy
  4. Run ‘top’ command on server

Result: Four processes for the application is running.

This was discussed earlier in How many instances of the application should XC spawn? - back then one instance per app was expected. Does the same apply now, or is four normal?

You get one instance per vCPU.

Thanks.
Does that also mean that:

  • one instance of the ‘app’ (WebApplication object) per vCPU is created? Or do they share one single instance?

In event handler for WebApplication.Opening we create a ServerSocket and start listening on a port.

  • Will listening only succeed for the first vCPU the app is started on (the following will fail since port is already taken)?
  • In practice - all clients connecting to the port are served by the same vCPU?
  • Yes, 1 instance per vCPU on the standalone apps on Xojo Cloud.

  • If you are using a ServerSocket, you’d need to make sure to have a way (via a file, sqlite db, etc) to know which port(s) had already been open. That’s correct, only one instance should be listening on a given port.

Yes. The first one will succeed and the second will fail. That said, I urge you to evaluate your need and consider using an http api through HandleURL if you can. Adding a second ServerSocket instance to your app (the built-in one being the first) can severely degrade the performance of the web app overall. The ServwrSocket does everything on the main thread, which means that while it is accepting and negotiating connections with its clients, it is blocking the web app from dealing with its own. Also, you don’t get any of the protections from bad actors that you otherwise do with the Apache Load Balancer running in front of your app.

1 Like

It’s also important to remember that unless you’ve built your app to handle this, if the instance that is listening crashes, the other one doesn’t just start listening in its stead. The crashed app will restart on its own relatively quickly and if the port is available, it will start listening again.

1 Like