Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 16, 2018 4:56 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: PostgreSQLDatabase in a thread
PostPosted: Tue Mar 26, 2013 10:53 am 
Offline

Joined: Tue Nov 18, 2008 9:19 pm
Posts: 25
I am using PostgreSQLDatabase in a thread. I create 10 of the threads. Each thread has it's own connection( using the dame db credentials) and works on an item. If I run only one thread it processes items very fast. As I start adding more threads the performance drops off. For example one thread takes a second two threads take two seconds three threads takes 6 seconds etc. So then I tried this. I started 10 processes running one thread each and it ran at fast for all 10. It appears to me like the PostgreSQLDatabase object is not thread save. Has anyone seen this behavior?


Top
 Profile  
Reply with quote  
 Post subject: Re: PostgreSQLDatabase in a thread
PostPosted: Tue Mar 26, 2013 11:16 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
rjohnsonvtp wrote:
I am using PostgreSQLDatabase in a thread. I create 10 of the threads. Each thread has it's own connection( using the dame db credentials) and works on an item. If I run only one thread it processes items very fast. As I start adding more threads the performance drops off. For example one thread takes a second two threads take two seconds three threads takes 6 seconds etc. So then I tried this. I started 10 processes running one thread each and it ran at fast for all 10. It appears to me like the PostgreSQLDatabase object is not thread save. Has anyone seen this behavior?


It *is* thread safe but you have to remember that threads in Real Studio are cooperative. A thread doesn't mean 'faster' it just means that you can have multiple processes going at the same time (but not executing simultaneously).

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: PostgreSQLDatabase in a thread
PostPosted: Tue Mar 26, 2013 12:12 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
If this is new instances of the same thread, you might be better off with a queue model instead.

Create a global property that acts as a queue and start your single thread. The thread opens a connection to the database, then checks the queue. If it finds something, it acts on it, then checks again. If not, it sleeps for some time.

Your main process simply adds items to the queue. As items are added, the running thread will process them sequentially, then remove them. I would expect this to be faster, but your UI might still lock up if the action within the database is time-consuming.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: PostgreSQLDatabase in a thread
PostPosted: Tue Mar 26, 2013 12:54 pm 
Offline

Joined: Tue Nov 18, 2008 9:19 pm
Posts: 25
Thanks for the response. That explains the problem. :(


Top
 Profile  
Reply with quote  
 Post subject: Re: PostgreSQLDatabase in a thread
PostPosted: Tue Mar 26, 2013 1:59 pm 
Offline

Joined: Tue Nov 18, 2008 9:19 pm
Posts: 25
Does anyone know if true threading is coming for Realstudio soon? The platform is serving us great on our Linux based, back-end server processes, but the lack of true threading is a "real" killer!


Top
 Profile  
Reply with quote  
 Post subject: Re: PostgreSQLDatabase in a thread
PostPosted: Tue Mar 26, 2013 2:46 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
If PostgreSQLDatabase.MultiThreaded is True then SQLSelect/SQLExecute shouldn't block. A long database operation will be handed off to Postgres via TCP and other RB threads will be free to do what they want, including sending more work to Postgres via additional connections. You can speed up database operations with an optimum number of threads in this case.

If the threads spend most of their time in RB code which prepares or processes the data, then the threads are just dividing time on a single core. More threads will not mean more speed in this case.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: PostgreSQLDatabase in a thread
PostPosted: Tue Mar 26, 2013 2:54 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
rjohnsonvtp wrote:
Does anyone know if true threading is coming for Realstudio soon? The platform is serving us great on our Linux based, back-end server processes, but the lack of true threading is a "real" killer!


No idea. At the bare minimum this would require improvements to CriticalSection and Semaphore, along with a thread safe memory manager. To be useful a significant portion of the RB framework would also have to be thread safe.

Note that this would not be automatic. Real would have to introduce either a Thread.Preemptive property or a new Thread class. And we would have to double check and rewrite our code to take advantage of it. There would be a lot more restrictions then we currently have with cooperative threads. Outside of a small domain of problems, preemptive threads are difficult to write and harder to debug.

That said, I do wish they would work on this.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group