Re: Multi-Threading
- From: "Alex Clark" <alex@xxxxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 17:44:49 -0600
This sounds a lot to me like you're using a hammer on a screw. If I
understand you correctly, you were having performance issues when reading a
100,000+ line log file and decided to use multi-threading as a solution to
this, which is seldom a solution.
Multi-threading on the desktop is useful when you're executing long running
blocking operations and want the GUI to remain responsive, running
background tasks and similar. Multi-threading on the server is useful if
you're servicing multiple requests simultaneously and perhaps want to take
full advantage of multi-core CPUs. It's nowhere near as useful for
improving performance as some people think it is; a program running a task
across 8 threads is NOT 8x faster than the same program running the same
task on just 1 thread.
Multi-threading should be used cautiously and when necessary as it can
create exactly the kinds of headaches you're having with your code. As
you've probably noticed from this thread, everybody has a different take on
how you should sync your resource access across multiple threads.
You need to investigate *why* your app is slowing down as it reads its way
through that log file. Are you allocating a new string each time you read a
line of the log file? Remember that strings are immutable, so once they're
created they won't be destroyed until the GC decides to. This could be
swamping your working set.
Is there a more efficient design pattern you could follow for reading the
file data and writing it into the database?
"Barkingmadscot" <barry@xxxxxxxxxxxx> wrote in message
news:36f3e01a-075f-4772-ac03-4cc59caf666c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am having problems with Multi-threading and write to Key Access
Database
I have a log file that and collecting infomation from
getting the info is a problem or is writing it the database, the log
files a big and it takes time to read down as it get further in to log
said, a 100,000 line in
I have changed it to mutli-threading which almost works, the problem
is when writing data to the table. I get dup keys and the whole
stops, this does not happen with the single thread app.
basically i want each thread to wait until thread before finish its
write to the database.
ie.
thread 1 waits for thread 0 to finish writing to table
thread 2 waits for thread 1 to finsih writing to table
thread 4 waits for ..........
during this each for the thread have collected the data they need to
write to the table.
Here is the line code to
Dim intcount As Integer = 1, intcount1 As Integer =
fNoOfLines(fileNm)
Dim AppThreads(4) As Thread
Dim WebData(intcount1) As DoWork
Do Until intcount > intcount1
WebData(Thread) = New DoWork
'################################
Code collecting data is here
################################
'# Setup and start new thread
AppThreads(Thread) = New Thread(AddressOf
WebData(Thread).sWriteWebUsage)
AppThreads(Thread).Start()
System.Threading.Thread.Sleep(15)
intcount = intcount + 12
Loop
I removed all the code that does the data collecting as it works
fine,
I believe my problem is at the Appthreads(thread).start()
.
- References:
- Multi-Threading
- From: Barkingmadscot
- Multi-Threading
- Prev by Date: Re: Object destruction VB.NET 2005
- Next by Date: Sudoku Solver question...
- Previous by thread: Re: Multi-Threading
- Next by thread: Get sql command in rowupdating event
- Index(es):
Relevant Pages
|