Page 1 of 1

How to set up multiple parallel running processes

Posted: Thu Aug 15, 2019 1:14 pm
by mrcoollion
Hello fellow LC enthusiasts,

I have a question about how to best setup multiple non blocking parallel running processes in LC.
What I am planning to build is an application that has approx. 20 processes running simultaneously.
Each process must get data from a Server in 30 sec intervals and communicate back in the same interval. I use TsNet for this (Post & Get) that uses a REST-API.
Each process has its own graphical user interface with controls and I have a overview interface.

So my question is, how best to set this up. Should or can I:
1) Place each process in a separate Stack and have a stack with the user interface and user controls that communicates with those other separate stacks?
2) Place each process in Sub-Stacks with each sub stack having the sub user interface a process controls. And the Main Stack handles the overview user interface and user controls and communicates with the sub-stacks?
3) Can I place all in one stack with cards and routines (Commands)?
4) Other options ?

So some much needed advice (maybe with example) would be appreciated so I will not be running in the wrong direction coming to the conclusion after having spend many hours that I need to start from scratch again?

Friendly greeting,

Paul (MrCoolLion)

Re: How to set up multiple parallel running processes

Posted: Thu Aug 15, 2019 1:18 pm
by Klaus
Dag Paul,

since LC is single-threaded, the only way to come near to your goal might be using "send" a lot.


Best

Klaus

Re: How to set up multiple parallel running processes

Posted: Thu Aug 15, 2019 1:45 pm
by dunbarx
I think I see what you are after, but why not just "thread" several processes. Given a field and a button with:

Code: Select all

on mouseUp
   doLotsOfStuff
end mouseUp

on doLotsOfStuff
   if the optionKey is down then exit to top
   put random(99) into fld 1
   wait 10 with messages
   doOtherStuff
end doLotsOfStuff

on doOtherStuff
   put any char of "XYZ" into fld 1
   wait 10 with messages
   doEvenMoreStuff
end doOtherStuff

on doEvenMoreStuff
   put any item of "Zebra,horse,dog" into fld 1
  wait 10 with messages
   doLotsOfStuff
end doEvenMoreStuff
Klaus' suggestion of sending messages in time would work as well. Each method invokes a well-formed handler, and these can be executed as desired, based on nothing, or any preset or other conditions.

Craig

Re: How to set up multiple parallel running processes

Posted: Thu Aug 15, 2019 2:49 pm
by Mikey
isnt tsnet asynchronous? if it is then you get multithreadedness by effect.
scheduling can be done lots of ways. i have a cron-ish library at https://github.com/macMikey/mikeys-cron-library. it is designed to be a levure helper but there is no reason why it cant be tweaked so that it is independent.
there are examples of running multiple lc threads/processes in various places. during last year's LCG there was a session on that very topic. it is very straightforward. you can also have multiple LC server instances running to do this.

Re: How to set up multiple parallel running processes

Posted: Thu Aug 15, 2019 6:25 pm
by FourthWorld
What is being done with the data during the time between downloading and re-uploading? And what is the size of the data being transferred?

Applications are often network-bound rather than CPU-bound, and the optimal solution will benefit from knowing which is the case here.

Re: How to set up multiple parallel running processes

Posted: Thu Aug 15, 2019 6:41 pm
by mrcoollion
Thanks for the excellent suggestions. I will test what fits best... and inform about the solution i finally choose.
@FourthWorld
The data send and received is very little so it should not be a source of concern.
The application has several processes running which are all similar (in fact exactly the same code but different parameters). At least Every thirty seconds maybe more often each proces requests data from the server and based upon this data and some algorithms does an action towards the same server or not.

Thanks for the help everybody and do not hesitate to place more suggestions of example code :D
Regards,

Paul (MrCoolLion)