How to set up multiple parallel running processes
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
How to set up multiple parallel running processes
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)
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
Dag Paul,
since LC is single-threaded, the only way to come near to your goal might be using "send" a lot.
Best
Klaus
since LC is single-threaded, the only way to come near to your goal might be using "send" a lot.
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9633
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to set up multiple parallel running processes
I think I see what you are after, but why not just "thread" several processes. Given a field and a button with:
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
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
Craig
Re: How to set up multiple parallel running processes
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 9820
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: How to set up multiple parallel running processes
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.
Applications are often network-bound rather than CPU-bound, and the optimal solution will benefit from knowing which is the case here.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: How to set up multiple parallel running processes
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
Regards,
Paul (MrCoolLion)
@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
Regards,
Paul (MrCoolLion)