threads - concurrent processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting threads - concurrent processing
# 1  
Old 09-05-2003
threads - concurrent processing

i have a program which uses a java thread that concurrently copies table data with many DB connections (one for each thread)

new to unix, wanted to know if its possible to do a similar thing in a shell script.

for eg

script.sh

trigger 2 stored procs at the same time which are independent of each other

set a flag in both of them just to know at the end.

is it possible in a shell script to do this

AIX server suports concurrent processing
# 2  
Old 09-06-2003
You're really asking two questions here. I'm not certain that you're clear on the difference between a thread and a process. But I will assume that you are and proceed from there.

First, I do not know of a shell with thread support. So as far as I know, no you cannot do threads in a shell script.

But it quite easy to launch processes in a shell script. And if you have multiple cpu's concurrent processing is easy.

In fact, concurrent processing is easy from the command line. Consider a command like:

ls -lR | grep mp3

If you have two cpu's, it is quite possible that both processes will run at the same time. No big deal here. But I have rewritten slow shell scripts to take advantage of multiple cpu's and I have seen a boost in performance.

Besides pipelines, you can put programs in the background. These may find their way into another cpu.
# 3  
Old 09-06-2003
thank you, that helped.

by thread i meant a java thread, i beleive it creates a seperate process in the background for each thread., not sure.

what i want is

sample.sh

Start
|
|
Copy detailtableA from one database to another (database connection 1)
Copy detailtableB from one database to another (database connection 2)
....
Copy detailtableN from one database to another (database connection N)
(I wanna do this simultaneously since they are not dependent on each other)
|
|
Get some flag when everything is complete
|
|
Copy master table from one database to another
|
|
End

The data is very important and goes from a production box to an archive box, so can't afford to lose data here.

I was able to do this in a Java program using threads, spanning many threads for each database connection and acheive the work, its pretty good.

But i want to know if i can do this in a shell script and stored procedure for each copy (row by row commit) it would be better, the volume is huge.

Thank you
dhaya
# 4  
Old 09-06-2003
Yes, as long as we're talking about processes and not threads, this is very easy.

You can launch a background job by just putting an ampersand on the end of the command. And the shell has a wait command. Use them like this:

some_program_or_script &
another_program &
and_another &
wait

Those three programs should run simultaneously. The script will stall at the wait command until they are all done.

Immediately after you launch a background job, its pid is available in $! and you can store this pid:

some_job &
pid=$!

And you can wait for this particular job to finish with:
wait $pid

This all works pretty well. The downside is that it is very hard for these jobs to communicate with one another or even to communicate results back to the parent. Temporary files are the usual solution.
# 5  
Old 09-06-2003
thank you, thats what i need to know.

writing and reading form files to communicate between each other right..

just one more thing, there are around 100 tables, so i am assuming creating that many processes won't affect any runtime etc.

thank you
# 6  
Old 09-06-2003
100 processes is too much unless you have 50 cpu's or more. I would not create any more than 2 processes per cpu as a max. And 5 or 10 processes would be more reasonable.

And remember that when you do:
something &
unless "something is a c program that does not fork, it actually may be several processes itself. Your os may prohibit you from creating many processes. On HP-UX maxuprc is 50 by default.

When there are processes waiting on the run queue for a cpu, the scheduler will switch processes so that they get a shot at the cpu. That's called a context switch and it can be expensive. Each cpu typically has enough on-board storage to remember how to run a few processes. But more than that and stuff must be reloaded from memory.

Since you are after performance, you should benchmark it. Increase the number of processes until it is counter-productive and then stop.
# 7  
Old 09-09-2003
thanks a lot , that helped me.

looking at threads now Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. AIX

Difference between concurrent and enhanced concurrent VG

Hi, What are the differences between concurrent and enhanced concurrent VGs.? Any advantages of enhanced concurrent VG over normal concurrent vg Regards, Siva (2 Replies)
Discussion started by: ksgnathan
2 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

Concurrent Processing in Perl Scripting

We are trying to scp files from machine A to machine B. We want to copy the files in the rate using the file original timestamps. Sometimes files have the same time stamp. So we want to start scp for all files with the same time stamp at the same time. I like to get some opinion on using... (0 Replies)
Discussion started by: meixingzhao
0 Replies

4. Shell Programming and Scripting

Concurrent execution

Hi all, I have a folder with sql files that need to be inserted in a DB with SQL*Plus. The thing is that it takes too long to insert them all one by one, so I want to insert them five at a time. Currently what I use is this: for $FILENAME in *.sql do sqlplus -s $DBUSER@$SID << EOF ... (0 Replies)
Discussion started by: Tr0cken
0 Replies

5. Shell Programming and Scripting

How to make parallel processing rather than serial processing ??

Hello everybody, I have a little problem with one of my program. I made a plugin for collectd (a stats collector for my servers) but I have a problem to make it run in parallel. My program gathers stats from logs, so it needs to run in background waiting for any new lines added in the log... (0 Replies)
Discussion started by: Samb95
0 Replies

6. Shell Programming and Scripting

concurrent processes

We have a very large text file..contains almost 100K lines. We want to process this file to generate another text file as per our data requirement. As for now the parsing of data takes 20-25 mins each , for 100K lines. the current script uses : While Read Each Line do parsing.. Done ... (6 Replies)
Discussion started by: Amruta Pitkar
6 Replies

7. UNIX for Advanced & Expert Users

No concurrent login

Hi, I notice in my Sun Solaris 8 sparc workstatin, I am able to login concurrently using a same user ID. Is there a way to disallow this? That is, at anyone time, the user can have only 1 login session. How can it be done? Thanks (10 Replies)
Discussion started by: champion
10 Replies
Login or Register to Ask a Question