Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

synclock causing bad performance?

Posted on 2004-09-16
4
Medium Priority
?
735 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 1200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 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