Hi everyone,
We are designing a Web Application (almost finished already) that will serve both as a full web application, as well as an application server (web services) using the HandleSpecialUrl event. The network is only internal (on a site) and the concurrent users would be from 5 to 10 (up to 3 full clients and the rest using the services).
Now my question is what is the safer / better use of the database? Are we safe with one persistent connection at the App.open (do we need to define something like critical blocks in it that should be executed without giving in to other threads) or do we need to connect separately in each client connection case?
You really should use one connection per session/client. If you ever want to use transactions, moving them all together will cause problems for you. You will also never know if the last error was caused by the currently cunning session or another one.
I wouldn’t. The overhead is negligible for multiple connections and since the requests are threaded, you’ll probably end up waiting more often than not.
For a classic use of WE, there is a database instance for each session. it works well.
For HandleSpecialUrl/handleUrl is trickier.
The simplest: Each connection (handleSpecialUrl/handleUrl), you open the database and you close it. Each time. I think it is safe (handleSpecialUrl/handleUrl is threaded), but it’s expensive.
Thank you Olivier. That is what I thought.
If I see there is a big overhead I might design a connection pool, and use already instantiated and Logged-on connections so that I “pay the price” once.
That’s what we’ve been doing but we started experiencing some hard crashes on Linux. We are still not sure why/how but it may be related.
We have a wrapper that handles an already set/connected db to the calling thread and once it’s finished this db is “marked free” again but not disconnected. We wrap everything with critical sections but still get the crashes. Not sure if switching threads too fast, too often (10s of times per second) is causing trouble.
What database? With only 10 clients, I can’t really imagine you will have any issues on a modern day processor. However, depending upon the database, there are ways to really cut down the cost of connections.