Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Nov 21, 2019 3:27 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Question on Threads in ConsoleApp
PostPosted: Wed Mar 02, 2011 1:50 am 
Offline

Joined: Wed Dec 22, 2010 7:41 pm
Posts: 7
Hi All,

I have a console application which consists of the following key items :
- ServerSocket with 10x TCPSocket's
- Module to perform command line Active Directory DS commands.

Originally, I had the TCPSocket DataAvailable pass the data directly to the Module - which would execute the command and return the result back in the same connection.
However, some of the DS commands take some time to complete, upwards of 60 seconds or more in some cases - during this time, the ServerSocket wouldn't respond to any other requests, and the remote user was in effect locked out waiting for the response.


So - what I've done is :

1) Created a module to act as a queue.
- New remote requests come in and get added to the queue. I return a 'OK' response to the remote user immediately.
- Any responses are added to another queue which the remote user can query at some later stage.

2) Created a thread, with a simple loop :
while true
WriteLog("Thread")
Check Queue
If item, action the request (this can take anywhere from 1 second to 60+ seconds)
add result to response queue
wend

3) In the main App, I initialized the thread, then the ServerSocket. Then I have a simple loop
While not(shuttingDown)
WriteLog("MainApp")
DoEvents(10)
wend



When this runs, and there is nothing in the queue - I get in my log
1s MainApp
1s Thread
1s Thread
1s Thread
1s Thread
1s Thread
1s MainApp
1s Thread
1s Thread
etc.

About 5 MainApp's per second - which is what I'm expecting

However, when there are items in the queue, I'm instead getting (depending on the time to complete a task) :
1s MainApp
1s Thread
4s Thread
5s Thread
9s Thread
30s Thread
35s MainApp
35s Thread
40s Thread
etc


Which isn't what I was expecting. I was still expecting the MainApp to trigger 5/6 times per second

What's worse - is in the 'longer' tasks that take more than 30 seconds - my remote clients cannot connect or timeout getting a response.

What have I done wrong ? How can I get my task to run without affecting the main loop - or more importantly - my ServerSocket to continue to accept / respond.

thanks

Kent.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on Threads in ConsoleApp
PostPosted: Wed Mar 02, 2011 2:13 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
If you issue a command in a Shell in synchronous mode (the default), it will block your app until it completes, whether it is in a thread or not. The shell just doesn't yield time back to RB so it can process other threads. You need to rework your app to use asynchronous threads.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on Threads in ConsoleApp
PostPosted: Wed Mar 02, 2011 2:14 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
to use asynchronous *shells*


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on Threads in ConsoleApp
PostPosted: Wed Mar 02, 2011 2:31 am 
Offline

Joined: Wed Dec 22, 2010 7:41 pm
Posts: 7
Tim,

Thanks - I didn't know that. I'll work on using using async shell command instead.

But that doesn't explain why, when it does return - that the thread still does another 4 loops before the MainApp ?

Or, is that because as far as RS is concerned - the DoDelay(10) time hasn't passed ?

cheers

Kent.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group