B4J Question Question about B4J server (chance apache to B4J)

Douglas Farias

Expert
Licensed User
Hello everyone, I will explain my current situation and with your help try to understand and solve my problem.

I currently have a VPS with 64gb of ram running Centos 7 Os, in this VPS I use apache / mysql for my applications.
I followed some internet tutorials to install apache, configure the domain in the vps, add SSL, and configure mysql.

I have no sites running, only API pages that are basically the following ...

App request (GET or POST) > PHP page get this data > PHP page make query on mysql > PHP page returns json to my apps.
it currently works ok with apache.

the problem comes now.

I am currently receiving many simultaneous accesses, millions and millions, my VPS is reaching the peak of CPU and RAM usage, I tried to follow some tutorials to tune Apache and mysql for this number of accesses and I was not successful.

I tried to switch to ngix, I got a significant performance improvement, less use of resources and more access. however my knowledge for this number of accesses is limited.

Today even with ngix configured, it reached a peak of 64 gb of ram and 100% of CPU usage, I will ask for an increase in server resources, maybe 128gb of ram but before doing this I wanted to see if the B4J maybe help here.

I have no knowledge of server, much less advanced apache and ngix, I wanted to try some solution with B4X
I will ask a series of questions, some are already on the forum, but even so I would like to confirm if you can answer me.

Questions about B4J Server on VPS

1 -
Is the B4J server ready to receive millions and millions of simultaneous accesses?
Is this tutorial ready to receive this number of simultaneous accesses or would it have to be configured and a different way to meet the number of accesses?
if you have to configure something to receive large numbers of hits, could you tell me how to do it?


2 - In the b4j server is it possible to point a domain and also configure an ssl certificate in an easy way? (https://www.something.com)
in apache this part was relatively easy, there are several tutorials on the internet, to set up a domain just edit some text files and that's it.
ssl is even easier, just use certbot, with a command line you install and it already configures a free ssl certificate.
how is this part in B4J? easy to install domain and ssl on a vps?


3 - what are the ways to configure a VPS to use B4J from the beginning?
let's assume I rented a new VPS, there is nothing in it yet.
would i have to install JAVA and MYSQL just right? once you install both just run the created .jar (server) and you're done?


4 - Is it worth it today to migrate from apache / ngix to B4J? can anyone here who has a lot of access tell me if it is worth switching to B4J? performance, number of accesses etc ...


5 - what happens when the number of accesses reaches the top in B4J (100% cpu and ram)?

in apache there is a queuing system, requests that cannot be answered at the moment enter a queue which ends up resulting in error 500 for some people, slowness etc ...
In a few moments apache stops working when ram and cpu reaches maximum, I have to manually reset it.

What would happen if at B4J I reach the maximum resources of the VPS?


6 - in apache there is a queuing system, when there are many requests at the same time, some get in a queue to be answered later, is B4J prepared for this? queuing system etc ...? do i need to configure something or is it ready?


7 - is it possible in B4J to receive a value via get or post and depending on the action do querys and return in json?

currently I don't have many pages in php, it is usually a single page, which connects to the mysql and also receives an action, depending on the action it makes a query and returns to the app.
for example
www.site.com/page.php?action=register
www.site.com/page.php?action=login


8 - B4J and MYSQL
even if the B4J supports and is prepared for everything I asked above. maybe mysql is not.
What would be the best way to configure mysql with b4j in this situation of many accesses?


9 - the b4j support headers values on the request?
on the apache/php i send via app some headers like login, values etc... the B4J server is ready to get this value easy?

I thank everyone
I remember again that I don't have advanced knowledge in programming, much less in the server (I didn't complete school). what I did until today was trying and trying.

any help is welcome...
 

Waldemar Lima

Active Member
Licensed User
1 - you can review this topic > https://www.b4x.com/android/forum/threads/server-performance-measures.37502/#content
2 - you can configure Advanced DNS in your domain provider ( https://help.one.com/hc/en-us/articles/360000799298-How-do-I-create-an-A-record- )
3 - review this topic :> https://www.b4x.com/android/forum/threads/server-run-a-server-on-a-vps.60378/#content
4 - see answer ( 1 )
5 - by the tests that I did, the server is only slow, but does not disconnect the user and does not terminate the application
6 - on the Jserver you can choose whether a Handler is multi-threaded or single-threaded
7 - the reading method (post, get, etc.) works the same as php, the difference is that PHP specifies the type of reading it wants to get ...
8 - if you have many simultaneous connections, it will require a little more of the hardware where your bank is allocated .... depending on the query the response is slow, but nothing that is unreasonable ..
9 - yes
 
Upvote 0

alwaysbusy

Expert
Licensed User
millions and millions of simultaneous accesses
simultaneous? Like at the same time? Like in 3.600.000.000+ requests/hour? Then you can forget it with ANY one server. We are then in the realms of server farms (buildings with tens of thousands of servers). The possibilities to use Horizontal scaling (as in adding power, RAM, CPU) is long gone. Vertical scaling (as in adding more physical machines to your server pool) is your only solution. In your case let's say one server can handle 2000 simultaneous requests, about 500 physical servers should do, but you would be cutting it very close. I would take 1000 to be at the safe side. But before your reached that kind of numbers, your MySQL database will have choked and gone up in flames...

The above is to illustrate this misconception of 'simultaneous' requests. Your Apache/PHP VPS with 64GB/128GB ram simply can not cope with such numbers. It will max out at a couple of thousands before it is dead. NGinx is good to do some scaling and having a couple of physical servers it can use to do the load balancing, it will certainly increase this number significantly.

You probably have a lot of calls indeed, but they are not simultaneous. In our company, our VPS provider did load testing on our server configuration, which is similar to yours (Dedicated server, Debian + MySQL + 64GB Ram). We have about a 10.000 hand held scanners that send over and receive data per REST API. On a daily basis they can make around a thousand calls each. Some scanners are not in range with a Wifi during the day, so a lot of them do send over the data at the same time when the shift has ended. (note that even here I don't write simultaneous).

We are running a jServer (ABMaterial) Web app on it, and a couple of REST API handlers (also based on jServer). Up until a thousand simultaneous (yes now I can use it ;) ) the server could easily handle it. It served the web pages, made lots of MySQl requests etc. Same with the API handlers receiving and sending json. Adding more and, like @Waldemar Lima wrote, the server became slower and slower, but still usable. As expected, at about 2000, it choked. It doesn't matter if it was jetty (jserver) or PHP, eventually this is bound to happen to any one server. As a matter of fact, Java (jetty/jServer) will probably do much better than many other servers.

This number may seem low, but in reality this is not bad at all. This will easily handle all our scanners during the day although it may have to handle many, many more requests. But because they are not simultaneous the server can process them all.

Our VPS provider monitors any choking point constantly and if ever this server has problems, our deal with them is that they will add/remove physical servers on the fly (in minutes). They use HAProxy (similar as NGinx) to do the vertical load balancing. But they don't expect this to happen for a long time, if ever.

So if you expect to have many simultaneous requests, you have to talk to a company specialized in doing this. You will not find answers here, and certainly will not be able to this yourself (no offense). This is a science in itself and although it fascinates me, I would never claim I would be able to set such a thing up myself. It is to fundamental to take the risk.

Good luck!

Alwaysbusy
 
Last edited:
Upvote 0

Douglas Farias

Expert
Licensed User
simultaneous? Like at the same time? Like in 3.600.000.000+ requests/hour? Then you can forget it with ANY one server. We are then in the realms of server farms (buildings with tens of thousands of servers). The possibilities to use Horizontal scaling (as in adding power, RAM, CPU) is long gone. Vertical scaling (as in adding more physical machines to your server pool) is your only solution. In your case let's say one server can handle 2000 simultaneous requests, about 500 physical servers should do, but you would be cutting it very close. I would take 1000 to be at the safe side. But before your reached that kind of numbers, your MySQL database will have choked and gone up in flames...

The above is to illustrate this misconception of 'simultaneous' requests. Your Apache/PHP VPS with 64GB/128GB ram simply can not cope with such numbers. It will max out at a couple of thousands before it is dead. NGinx is good to do some scaling and having a couple of physical servers it can use to do the load balancing, it will certainly increase this number significantly.

You probably have a lot of calls indeed, but they are not simultaneous. In our company, our VPS provider did load testing on our server configuration, which is similar to yours (Dedicated server, Debian + MySQL + 64GB Ram). We have about a 10.000 hand held scanners that send over and receive data per REST API. On a daily basis they can make around a thousand calls each. Some scanners are not in range with a Wifi during the day, so a lot of them do send over the data at the same time when the shift has ended. (note that even here I don't write simultaneous).

We are running a jServer (ABMaterial) Web app on it, and a couple of REST API handlers (also based on jServer). Up until a thousand simultaneous (yes no I can use it ;) ) the server could easily handle it. It served the web pages, made lots of MySQl requests etc. Same with the API handlers receiving and sending json. Adding more and, like @Waldemar Lima wrote, the server became slower and slower, but still usable. As expected, at about 2000, it choked. It doesn't matter if it was jetty (jserver) or PHP, eventually this is bound to happen to any one server. As a matter of fact, Java (jetty/jServer) will probably do much better than many other servers.

This number may seem low, but in reality this is not bad at all. This will easily handle all our scanners during the day although it may have to handle many, many more requests. But because they are not simultaneous the server can process them all.

Our VPS provider monitors any choking point constantly and if ever this server has problems, our deal with them is that they will add/remove physical servers on the fly (in minutes). They use HAProxy (similar as NGinx) to do the vertical load balancing. But they don't expect this to happen for a long time, if ever.

So if you expect to have many simultaneous requests, you have to talk to a company specialized in doing this. You will not find answers here, and certainly will not be able to this yourself (no offense). This is a science in itself and although it fascinates me, I would never claim I would be able to set such a thing up myself. It is to fundamental to take the risk.

Good luck!

Alwaysbusy
sorry, i expressed it wrong, there are millions a day, per second i believe it is between 30 to 100. there are peaks and falls.
anyway i will try to do a test with B4J, see how it will do.

here is a video (today, today would be a calm day, low traffic. this in 45gb of ram used.)

Thanks for the infos
 
Upvote 0

DonManfred

Expert
Licensed User
Upvote 0

alwaysbusy

Expert
Licensed User
there are millions a day, per second i believe it is between 30 to 100
That was what I expected :)

a 100/s will not be a problem, I suspect even a 1000/s will just be fine.

jMeter is a good tool to do load testing, although it is a pain in the a$$ to setup. I did it a couple of years ago, but gladly gave it in the hands of the professionals
 
Upvote 0
Top