Performance problem with my website, advice and help needed

Patrick, Hi!
Thank you for the feedback.
Understood, we will try to configure nginx/passenger.

Alternative it is also possible to make some small changes to the js code to have a cluster.

https://nodejs.org/dist/latest-v16.x/docs/api/cluster.html

Important to know is that memory is not shared between the processes, so for things like sessions you should not use memory storage and also for your sockets I would advice using Redis.

1 Like

Patrick pretty much summed the problem - NodeJS is a single-threaded app, so you need to run multiple instances in parallel to take advantage of a multi-core processor :slight_smile:

https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_min_instances

I’d recommend doing this at Passenger/nginx config rather than using NodeJS’s clustering, primarily because you’d be deviating from standard Wappler code that could be overridden with an update.

And just to elaborate a bit more, looking at the CPU graph, you see there’s a tendency to form an upper-bounded line at 20% CPU usage - this implies one CPU core is at 100%, while the rest are unused. 100% / 6 cores = 20% / core

On the SSH terminal you can use the command “top” to view CPU usage per-process. You could also see that way how many “node” (NodeJS) processes are running to confirm you have multiple instances running in parallel (or you can run “pgrep node” as well)

Good luck! :slight_smile:

P.S.: I’m busy, but if you truly get stuck feel free to reach out for a paid consultation

4 Likes

Thank you a lot for the addition!
I definitely see the situation more clearly now.

Seems like the problem is narrowed down, so I hope the hosting support will be able to find the solution.

1 Like

@patrick @Apple I almost forgot to write a follow-up.

So I sent your thoughts and links to my hosting support and they managed to set up multiple instances for nodejs.
And the website really began working smoothly with the ability to hold much more users then before.

So again, big thanks for the help, guys! You really saved the day back then.

Although, indeed, this caused some problems with sockets. It wasn’t critical for the project though. I’m about to solve this too.

To solve the sockets and session problem I suggest to use Redis which we support directly from Wappler, there are other ways like using database or the filesystem to store the data that needs to be shared between the processes.

So, let’s imagine I have:

  • nginx is configured on the server to support multiple NodeJS instances,
  • Docker Hosting for hosting and NodeJS for server model,
  • build-in Redis enabled and it enabled for required server actions and pages.

It would already work alright?
Or should I make additional manual settings for Redis?

In the Server Connect Settings enable Redis in the Redis tab and in the Sessions tab set the Session Store to redis. With redis enabled you can also use the Cache Time property on routes that may be cached. Sockets will automatically use redis when it is enabled.

Got it, thanks! So basically everything preinstalled out-of-the box, cool.

By the way, regardless of this topic overall – is it technically possible in the future to make Wappler itself to set multiple instances web apps in order to take advantage of a multi-core processor? Without help of hosting support or any other kind of professional assistance.

Do you mean the Wappler app or your nodejs site?

I mean nodejs site

We can make multiple instances easily, but most hosting already offer this. It is better to use a good process manager like Pasenger which is used by your host or something like pm2. The advantage of such process manager is that it runs separately from the node app and it handles crashes, large memory use and also logging.

Also as you know there are some extra issues with running multiple instances, like sessions and sockets must use some persistence storage to share there data between processes. This is easy with Redis, but not everyone has Redis.

If there are more requests for multiple instances we will perhaps include it. It is easy to implement with the cluster api. Cluster | Node.js v16.14.2 Documentation (nodejs.org)

3 Likes

Thanks! Understand you, will see.

But what do you think about this quote below? Basically, it is not the best way to use pm2 or Cluster, because changes can be altered after some update?

That would be very appropriate. Some of my projects use private servers and sometimes there are performance problems. Nothing critical yet, but if the user load increases, it will become critical. To be able to configure the cluster directly from the Wappler would be just perfect.

1 Like

pm2 is fine, I was referring to a built-in NodeJS clustering functionality

Didn’t even cross my mind to use something like pm2 in front, I think that’s an acceptable solution

1 Like

@patrick @Apple So, I decided to try to manage the project using Docker Hosting instead of Plesk I’m currently using. It will cut off the websockets problem.

The question is, how to correctly configure multiple instances in that case.
If I’m gonna use Docker, then it must be settled somewhere in the project itself, right?

Considering I have no experience in administering Docker, nodejs or whatever, do you think I would be able to configure it myself following instructions? (via clustering or pm2 or any other way) Is it a complicated process?

I don’t use Wappler’s Docker deployment, but can you check if you can find an option called “Replica” or “Scale”? And just increase the number (and that’s it!)

I’ll investigate it, thank you!

I’ve created FR about the matter we discussed here.

1 Like