Solved

synclock causing bad performance?

Posted on 2004-09-16
4
691 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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