Share My Creation [Project Template] Web API Server

Pendrush

Well-Known Member
Licensed User
Longtime User
As general rule you should open connection for client, when server return result connection should be closed.
Better way is to use some MySQL (MariaDB) connection pool. As open/close connection is expensive. When client request connection "hot" (pool) connection is given to the client. On connection close, connection is returned to the pool. HikariCP is my preffered.

Pool performance chart:

 

ilan

Expert
Licensed User
Longtime User

sorry, but I have not understood your answer. only 1 client is making the connection. all other clients are just making get/post requests to the webapp.

anyway, I have opened a new thread since I don't want to make a big mess in @aeric's thread.

 

aeric

Expert
Licensed User
Longtime User
You can do an experiment if you don’t believe you need to close the connection. ?

I share my experience here. I have jAdmin hosted in my VPS and I didn’t close the connection correctly last time. I also didn’t set the MaxPoolConnection. Then after a few minutes, the app cannot be access. The server has reached the default maximum number of connection.

REST API is designed to be stateless. It is different from web socket. However you still can keep user session in server.

Let say I am making a Get request from Chrome, which involve a database query, a connection is made. Then I make second call to the same request, a new connection is made. So after a while, many connections are made. I may close the browser and open again multiple times and each time, a new connection is created. The server doesn’t do garbage collection and not smart enough to close the connections for me automatically. It doesn’t know if you don’t implicitly close it. This is my understanding.
 

juangtju

Member
hi excuse me , i use your example for create a web app with connect to a mysql database , but i dont know how is the procedure to consult a new database for save record in other database with other field on it created in a form, you can help me with that??
 

aeric

Expert
Licensed User
Longtime User
I construct the database table using script.
You can check queries_mysql.ini inside the Objects folder. The MySQL connection username and password are set in config.ini
You can also design your own database using other tools such as Heidi, PHPMyAdmin or Adminer.
 

tchart

Well-Known Member
Licensed User
Longtime User

Slightly off topic but I recently did some tests with HikariCP and I got worse performance compared to having a single DB connection (defined in Main). I did some further reading on this and having a connection pool offers no advantage for a local database.

This was doing the same stress test I've documented on here before. Using the H2 database I get about 4000-5000 requests per second. When run with HikariCP it goes down to 1500-3500 requests per second (I noticed it did fluctuate a lot).
 

aeric

Expert
Licensed User
Longtime User
Can I summarize that it is sufficient to use the normal connection pool as Erel’s example?
 

tchart

Well-Known Member
Licensed User
Longtime User
Can I summarize that it is sufficient to use the normal connection pool as Erel’s example?

I would say yes, if you are using a TCP based database connection (eg MySQL, Postgres etc) then it makes sense to use a pool.

If you are using a file based database then don't use a pool.
 

juangtju

Member
yes i know that , the problem is not the creation of a new table , i have the existing table with i workaround , but who i dont know is how to call these tables in a b4xtables example you have posted here , that is my principal problem
 

aeric

Expert
Licensed User
Longtime User
yes i know that , the problem is not the creation of a new table , i have the existing table with i workaround , but who i dont know is how to call these tables in a b4xtables example you have posted here , that is my principal problem
You can post a new question. I think you can’t send me a personal message since you are new here.
 

aeric

Expert
Licensed User
Longtime User

aeric

Expert
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…