Solved

synclock causing bad performance?

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now