RTC Forums

Subscription => Support => Topic started by: iwaass on February 20, 2019, 01:05:35 PM



Title: Multiuser and Sqlite database
Post by: iwaass on February 20, 2019, 01:05:35 PM
Hello!

I have the following requirements for a project:
A) Server can be run on any platform - therefore I used SQLite as database
B) Server can be connected from many clients (mobile App)
C) Server has to handle multiple requests at the same time

Now my question:
RTC can handle "normal" requests fine from multiple users at the same time.
BUT when I have a "Single user" database -> SQLite in place - things got complicated.
How should I handle the requests? Some queue?
Does someone has similar projects?

PS: I really love RTC!!!  8)


Title: Re: Multiuser and Sqlite database
Post by: D.Tkalcec (RTC) on February 20, 2019, 01:26:47 PM
You can run your RTC Server in a single-threaded mode by setting its "MultiThreaded" property to FALSE (default value), which would result in all your events executing from the Main Thread (synchronized when your Server is running on a non-Windows platform). The alternative would be to learn how to use the database of your choice (SQLite) in a multi-threaded environment. Multi-threaded programming is NOT specific to RTC, but applies to any Application where code can be executed from more than one thread at a time. If you need help with that, you can either Google about using critical sections in Delphi (TCriticalSection), or ... you could try asking the SQLite Team for support with their product (since this is technically an SQLite question):
https://www.sqlite.org/support.html



Title: Re: Multiuser and Sqlite database
Post by: iwaass on February 20, 2019, 01:47:28 PM
Thanks for your input.
Server is running fine with more clients at the "same time" and can work with the database (multithreaded=False).
Issue is the server itself.
One person is working on the server directly (same functions like clients + additional ones).
Question is how to synchronize the DB access between clients (RTC calls) and server DB access.
Can I use the "same pool" or any other technique to do it?
On solution can be to call the server from the server to use the same framework... :)
But is this really the best solution?  ???


Title: Re: Multiuser and Sqlite database
Post by: D.Tkalcec (RTC) on February 20, 2019, 02:02:31 PM
If you are asking for my opinion, using the same process to act as a Server for multiple users connecting remotely and as a direct access point for a single user sitting in front of the Server PC is a bad idea. IMO, the Server should ONLY be responsible for handling remote requests. If you place a user in control of the Server process, you are adding an unknown to the equation and increasing the risk of user-made problems, even without the added complexity of maintaining multiple ways for users to access the same data (local and remote).

If your RTC Server is running in single-threaded mode (MultiThreaded=FALSE), unless you create Threads manually, all your code will be executed from the Main Thread. In that case, your entire Application is basically single-threaded, which eliminates the need to manually "synchronize" code. But, it also means that any remote user sending a request to the Server is going to "block" the user working with a Form created by the Server process directly, and vice-versa.

The easiest solution there would be to NOT have ANY users working with the Server process directly, but do everything remotely. By using "localhost" as the Server address, you can have a local Client process connected to your Server process the same way all the remote Clients connect.


Title: Re: Multiuser and Sqlite database
Post by: iwaass on February 20, 2019, 03:06:14 PM
Actually I cannot avoid that users are working on the server.

Project in detail:
Server is a POS (point of sale) solution. This main application is now used on any platform (Windows, iOS, Android).
Now I wanted to add mobile support -> so waiters can send orders to the main application.
Still they have also some tasks directly on the main POS solution.
Therefore I need the possibility to read/write on both sided (server, clients).
It will be a challenge to implement this behavior on a single-user database. :)
But what can I do....


Title: Re: Multiuser and Sqlite database
Post by: D.Tkalcec (RTC) on February 20, 2019, 03:43:53 PM
I've given you all the options, but you need to choose the best approach for your Project. Good luck.