The OP said he was successful in splitting his huge file and putting each chunk into a thread for processing, but was unsure on how to collect the output generated by each thread. He said a database write was unacceptable to his boss. The concept of each thread writing to it's own output file and merging them after script completion didn't appear a good solution to him, or else he wouldn't have brought the issue up. Consider a situation where the threads process millions of records, but only need to report back a few matches. This method will allow the main thread to collect those matches, and operate on them in realtime. Otherwise the main thread would have to tail the thread's output files.
| [reply] |
Hm. I guess I read the OPs post differently.
His task description is: read records from a (single) huge file, and write them to one of many (600) output files depending upon their contents. He asked how he could use thread to improve the performance.
You suggested splitting the huge file into several smaller files so that each thread could work on a different part.
He pointed out that would mean he would have many threads writing to each of the output files.
You are suggesting that he has many pipes and another thread running a select loop to coalesce the records for each output file before writing them.
Lets say he has split the huge file into 10 parts and he runs 10 threads. Using your schema, he would require one pipe for each of the 600 output files in each of the 10 threads; and another 600 threads running select loops to coalesce the records and write them to the 600 output files. So 610 threads and 6000 pipes!
And that's before we consider that he has exasperated the problem by reading the input from 10 separate files concurrently, which will cause the read head to be dancing all over the disk just to get the input.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
Lets say he has split the huge file into 10 parts and he runs 10 threads. Using your schema, he would require one pipe for each of the 600 output files in each of the 10 threads; and another 600 threads running select loops to coalesce the records and write them to the 600 output files. So 610 threads and 6000 pipes!That is not how I see it being done, and you clearly misunderstand what the
pipes are doing, and as usual you use incorrect math to make the problem seem worse, somehow hoping it will prove your point. Not today, my man. First there would only be 10 pipes, if there were 10 threads. The main thread can open as many disk files as it wants, and as the data comes into the select loop, some logic can be applied to determine which of his 600 output files it gets written to. The select loop would act as a central collection point/filter,
allowing one piece of logic to decide where any thread output should be ultimately be written. Its simple: the threads write to the select loop, the select loop decides where the particular data should be written. Otherwise he would need to incorporate the logic for which file to output to, into each thread, AND THEN have to worry about flocking those files. My method avoids that flocking problem by making the select loop the master disk writer and filter.
| [reply] |