queries & thread

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
yar
Posts: 15
Joined: Sun 23 Mar 2014 10:47

queries & thread

Post by yar » Mon 21 Aug 2017 16:43

I am developing a server that answers requests from a running application on my smartphone or browser.

Each request is in json and then there is a function that runs a query against the SQL server. The answer I translate to json and return to her.

There are situations where there are more than 150 queries, each query can even take a few seconds.

Do your components support such a solution?
Do you have an example?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: queries & thread

Post by azyk » Tue 22 Aug 2017 10:04

There is no separate component with the implemented functionality of a server application. As one of the solutions you can use UniDAC + DataSnap technology. You can see the sample in our blog:
http://blog.devart.com/using-dac-produc ... pment.html .

To solve the described issue, you can use the above solution or any other one.

P.S. UniDAC allows developing custom apps that can connect to remote ASE directly without using a three-tier application for the following platforms:

-Windows, 32-bit and 64-bit
-MacOS
-Linux, 32-bit (only in Lazarus and Free Pascal) and 64-bit
-iOS, 32-bit and 64-bit
-Android
-FreeBSD (only in Lazarus and Free Pascal) 32-bit and 64-bit

yar
Posts: 15
Joined: Sun 23 Mar 2014 10:47

Re: queries & thread

Post by yar » Tue 22 Aug 2017 14:08

I'm not using DataSnap. I use another component of ipworks that manages the server references.
I saw the example you sent me but when I run TUniQuery I can not run another TUniQuery until the first one does not give an answer.
In fact, if there is a query that takes a few seconds, all the other calls are pending.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: queries & thread

Post by azyk » Wed 23 Aug 2017 10:39

In order not to wait for SQL query execution completion, you can execute each of them in a separate thread. To ensure thread safety in UniDAC, you should use a separate instance of TUniConnection for each thread. For this, you can create a separate TUniConnection component for each thread in Datamodule and pass its TUniConnection component to each thread, or create a separate TUniConnection instance in each thread in run-time.

To minimize the time for creating TUniConnection instances, you can use UniDAC Connection Pooling. For this, before establishing a connection set TUniConnection.Pooling to True. More information about UniDAC Connection Pooling in our online documentation: https://www.devart.com/unidac/docs/?work_pooling.htm

yar
Posts: 15
Joined: Sun 23 Mar 2014 10:47

Re: queries & thread

Post by yar » Wed 23 Aug 2017 19:13

When I manage each query in a separate thread it is indeed possible to run parallel multiple queries.
The problem now is that when there are 200 threads at the same time (when the entire system receives thousands of calls but there are about 200 calls remaining in the air waiting to receive a result and close the thread)
When some run long queries (20 seconds) the system gets stuck.
I manage everything in a dynamic array and despite everything there are blasts - as if some of the thread get stuck.
what can be done?
Maybe the thread is not built for loads?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: queries & thread

Post by azyk » Mon 28 Aug 2017 12:28

Please provide the exact error message(s) if you get ones before thread crash/stuck. You can use logging in your application to detect the exact places where errors occur or the sequence of actions that leads to them. Try to get a stable reproduction of the issue and then compose a small test project to demonstrate it. You can send the test project using the contact form on our site: https://www.devart.com/company/contactform.html .

Post Reply