Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
In my MFC dialog based application there are 2 parent threads and inside the parent thread there are 3 child threads and these are synchronized using CEvent-- SetEvent() and ResetEvent().
The input file is readed as blocks of 16 char.Shared buffer is used for storing the blocks.

child thread1 -- used for read a block(16 char) from file1
child thread2 -- used to perform some task on block readed by thread1
chikd thread3 -- used to write the modified block to file2

These three child thread are in while loop until block > 0.

The child thread1 sets event for child thread2 and child thread2 sets event for child thread3.

The run time performance of the application is very poor for the large files. How can I increase the performance as the application runs very slow?
Posted
Updated 27-Apr-10 8:59am
v2

Pure, of course:
you have lost the multithreading processing by this technique,
since your threads are working nonparallel... :)

I would solve it like following:

0. Control the file access by a critical section (for thread 1 und 3)

1. Allocate a protected by a second critical section the whole-sized buffer

2. Control the "clusters" of the buffer in a cluster list protected by a third critical section

2a. The first thread read a block by block from the file in its loop and
2aa. fill the buffer by the read cluster
2ab. make an entry in the list with the flag "ReadyToModify = true, BlockOffsetInBuffer = x, BlockLengthInBuffer = y"

2b. The second thread iterate the list to find the next entry marked by "ReadyToModify = 1"
2ba. read the cluster from the buffer to a local buffer
2bb. modify the local buffer
2bc. fill the buffer by local modified cluster
2bd. set the list entry flag "ReadyToSave = 1"

2c. The third thread iterate the list to find the next entry marked by "ReadyToSave = 1"
2ca. read the cluster from the buffer to a local buffer
2cb. save the local buffer in to the file
 
Share this answer
 
First: when talking performance, you need to show numbers. One can only guess _why_ the app is slow.

However, one figure that jumps out of your question is the number 16: "read 16 characters from file1"...

File access is amongst the most expensive in a program: disk latency etc... Your program seems to be IO-bound. You could try to figure out whether the bottleneck is the file-IO; I assume the answer will be "yes".

Assuming file-IO is the bottleneck, try to limit it: read bigger chunks at a time, thus ruling out the disk-read overhead.

And: don't expect magic: 'larger' files will take 'larger' amounts of time. The question is if it's within reason.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900