Solved

synclock causing bad performance?

Posted on 2004-09-16
4
673 Views
Last Modified: 2009-07-29
I am using threads to process some information and then construct a SQL insert command to be included in a batch insert to the DB.  I setup a global variable to store the batch commands and also a counter to keep track of the number of pending inserts.  I tried to use synclock to lock the two global variables while they are updated but this code section seems to be causing my app to work up to 100% cpu usage.  I'm really at a loss as to how to troubleshoot this issue.  Does anyone have any suggestions?

       'construct the SQL insert statement = strSQL

        SyncLock BatchSQL
            BatchSQL.Append(strSQL)
            BatchSQL.Append(";")
            BatchSQLCount += 1
        End SyncLock

       'End of thread
0
Comment
Question by:stealth188
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12080267
Do you feel that threading will provide enough benefit to outweigh the complexity that it brings to your solution?  Are the SQL operations optimized?  Are there other bottlenecks that might prove to be more beneficial?

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12080350
Yeah multithreading is required to get the performance I need.  I'm sure that it is related to the synclock because when I remove it the processor goes back to being nice, although the app doesn't work correctly because of multiple threads accessing global variables at the same time.  The queries are optimized as best as can be for adhoc queries, all that i want to do it make sure that the global variable batchSQL is protected from corruption.  I was trying to use stringbuilder to concantonate the string because MSDN says it is faster than just doing a simple &.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 400 total points
ID: 12083679
You need to make sure that you are avoiding deadlocks:

Example:

Lab 6: Monitors and Thread Synchronization 2
http://astha.8m.net/CPwJ/lab6-1.html

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12085414
You got it.  I had found this last night when puzzling over it some more.  Had a situation where threads were calling threading and locking during those activities.  Thanks for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql server, import complete table, using vb.net 9 53
Vb.net threads keep increasing 2 50
Name Space error VS2015 1 37
Need help with a query 3 39
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question