Question

concurrent run - help needed

Asked by: jnefer

Hi,
We have a requirement to execute a Sybase stored procedure concurrently with 2 or more instances based on the need. Each instance will have different input parameters. This stored procedure has multiple inserts and updates to a single table. And each instance of the SP will populate and update records greater than 50000. Some even upto 200000!
We made the following configuration changes in Database
1)      Changed the row and page lock promotion threshold HWM to 15000
2)      Increased the no of locks in the adaptive server to 200000
Made the following changes in code
1)      Placed each insert and update query within a transaction and added logic to commit each query transaction after every 10000 records were processed. Basically each query is executed in a batch of 10000
2)      Table was created with DATAROWS lock schema
Is this a good approach to achieve concurrency? We tested this approach above and we did not run into deadlocks or exhaust locks in the server but the total run time was increased. We have added a condition in all insert queries to check that record that was inserted in the previous batch loop is not inserted again. so we wonder if that condition increases the run time. not sure though.
Will increasing HWM to 15000 cause a problem? Will it be a better idea to increase the current batch size to 50000 and also increase the lock promotion threshold HWM to a value greater than this batch size?
Providing solutions/ suggestions  as soon as possible will be of great help!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-14 at 06:01:24ID24810990
Tags

Sybase

,

Concurrent Processing

Topic

Sybase Database

Participating Experts
1
Points
500
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Partial Commit
    I would like to write a stored proc. and update a table in the stored proc. and there is a trigger on that table to log the process. No matter the stored proc is successed or failed. the Log should be commited. How to rollback back the stored proc updated data but commit the...
  2. Exhausted Result set
    I have a stand alone jsp page that is using an sql string to create a result set from an Oracle db. I have tested the sql string by itself and it returns one row. When I use it like the following I get the error in Tomcat "Exhausted ResultSet" I close the result set...
  3. Concurrency
    Hi I need an article about concurrent programming, I must be prepared to present it in class next week I also need to talk about new experiences/advances in this field that have been achieved in the past 2/3 years (50% of the grade) any help would be appreciated.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Joe_WoodhousePosted on 2009-10-14 at 21:09:31ID: 25577145

Your results are correct and expected - most measures to improve throughput (concurrency) reduce response time. Batching commands will be slower than doing entirely set-based operations one data set at a time. Datarows locking slows down response times as well.

I'd suggest if you're going to play with lock promotion thresholds, set those for the session in these stored procedures rather than globally with sp_configure.

Also if your tables here are all datarows locked, there is no need to change the page lock promotion thresholds - row-level locking escalates directly to table locking if there is a lock promotion.

This last point is crucial - have you actually seen lock promotions if you don't tune the promotion thresholds? They happen less often than you might think... The best way to prove they occur is to run sp_sysmon during your concurrency tests and look for lock promotions - if sp_sysmon reports none, there were none and you don't need to tune these settings at all.

Your basic approach seems sound though.

 

by: jneferPosted on 2009-10-15 at 02:47:05ID: 25578847

Thank you Joe,
I generated the sysmon reports and there were 24 Ex-Row to Ex-Table and 2 Ex-Page to Ex-Table promotions. But i'm not sure if this is related to this process in question as a few other processes were running at that time. However, i did not see any lock promotions from the sysmon report when the threshold was set to 15000 at the server level.
I shall look at generating the report again with executing only this process.
Will partitioning the table provide better results?

Thanks,
jennifer

 

by: Joe_WoodhousePosted on 2009-10-15 at 03:08:49ID: 25578980

sp_sysmon: Yes, this reports on all activity server-wide, so you still don't actually know for sure if you're seeing any lock promotions during your inserts and updates. Most table locks are due to a lack of usable WHERE clauses and optimiser decisions, I think genuine lock promotions are actually quite uncommon.

The only downside to setting lock promotion thresholds very high is that you might run out of locks. If you have enough memory to configure for plenty of them, then go ahead. :) (Keep running those sp_sysmons though - you might start seeing things like address lock contention, etc, requiring some attention.)

Partitioning the table will not help you here. Partitioning helps two scenarios, but neither of them apply to you here. It helps distribute last-page blocking on inserts and updates to heap tables... but you're already using datarows locking, which does a better job and won't be improved much if at all by table partitioning. It also helps parallel query performance... but you inserts and updates can't use parallel query. So don't bother.

 

by: jneferPosted on 2009-10-19 at 03:01:29ID: 25603821

Hi Joe,
Based on your suggestions, I'm going to suggest following recommendations to achieve concurrency. please let me know if this is sound.  
1) Increase number of locks to the maximum possible. Atleast to 500000
2) Modify stored procedures to execute each query in a batch of size 30000. Commit transaction after each batch loop. This will release locks obtained by the transaction.
3) HWM threshold to be increased to the size of the batch which will be 30000. The only set back as you said in increasing the HWM very high is that we might run out of locks.  But since we are releasing locks by committing the transaction after each batch loop this situation will be eliminated (right?)
Also HWM will NOT be inreased at the server level. change HWM for only those tables affected.

Setting the HWM to a high value is to just avoid even the rarest possibility of a genuine lock promotion. Please let me know if i'm wrong in this understanding

Thanks,
Jennifer

 

by: Joe_WoodhousePosted on 2009-10-19 at 03:37:33ID: 25603974

> 1) Increase number of locks to the maximum possible. Atleast to 500000

If you aren't seeing messages in your ASE error log saying you're run out of locks, you don't need more.


> 2) Modify stored procedures to execute each query in a batch of size 30000. Commit transaction after each batch loop. This will release locks obtained by the transaction.

More frequent commits definitely improve concurrency, this is the single best thing you can do. You may want to test smaller batch sizes, perhaps 20,000, 10,000 and even 5,000? Don't forget to explicitly test for and deal with scenarios where one batch commits but another does not...


> 3) HWM threshold to be increased to the size of the batch which will be 30000. The only set back as you said in increasing the HWM very high is that we might run out of locks.  But since we are releasing locks by committing the transaction after each batch loop this situation will be eliminated (right?)

You do indeed get locks back as transactions commit (or roll back). I'm not sure this is the best way to deal with this, though - the HWM says "you must attempt to promote locks to table locks when you hit this many locks on the same object in the same statement". Note that last word!! Lots of one-row writes in separate statements will not trigger a lock promotion, the promotion is tracked per statement.

Also for what you're trying to achieve you should also set the LWM to the same number - this means "never attempt lock promotion below this number", which seems more to be what you're after.

Honestly lock promotion thresholds usually don't need much attention. If your transactions are short and small, and you're using datapages or datarows locking, most of the time that's good enough.

I strongly recommend you test your code while running "sp_object_stats" - it takes a syntax very similar to sp_sysmon, and it reports on where the lock contention is. You may find it isn't on these tables at all...


> Also HWM will NOT be inreased at the server level. change HWM for only those tables affected.


I think that's a mistake, one size does not fit all. You can't say all access to these tables would benefit from those settings. Far better to set them at the session level in the procedure itself.

 

by: jneferPosted on 2009-10-21 at 22:54:50ID: 25631156

Hi Joe,
we ran sp_object_stats and we found there were no lock contentions. the message below was printed in the report.
No contention on any tables!
But we noticed that one of the huge tables got excalated to a table lock. Could this have been avoided if the HWM was increased?
FOllowing was the config setting in th Database and procedure
1) No of locks --> 500000
2) LWM and HWM --> 200
queries were executed in batch of size 25000 with frequent COMMITs. Both jobs finished successfully.
please let me know if you want me to publish the entire object_stats report.
We also looked at the query plans and noticed that the query was going for a deferred update instead of a direct due to a "not exists" condition that we introduced to achieve batch control. (adding this condition was an attempt to make sure record that was inserted in the previous batch loop is not inserted again in the next loop)
This deferred update increases the total run time of the procedure.
Appreciate your help and assistance and thanks in advance!

Thanks,
Jennifer

 

by: jneferPosted on 2009-10-21 at 22:56:16ID: 25631159

how could we eliminate the deferred update and still achieve the batch control?

 

by: Joe_WoodhousePosted on 2009-10-21 at 23:07:05ID: 25631196

> we ran sp_object_stats and we found there were no lock contentions

That's pretty conclusive! You have no lock contention (during that test).


> But we noticed that one of the huge tables got escalated to a table lock.

Do you mean you noticed that it used a table lock, or that there was a lock promotion? I don't know of any way to say the latter for sure without sp_sysmon...

This goes to what I said earlier - most causes of table locks are not actually lock promotions, and playing with promotion thresholds won't do anything useful. The number one cause of table locks are table scans. Possibly your deferred update caused this...?


> Could this have been avoided if the HWM was increased?

Only if it was caused due to a lock promotion; it's not yet clear that one occurred.


> how could we eliminate the deferred update and still achieve the batch control?

One suggestion: put PKs of rows to update into a holding table (row-level locked), delete from holding table within same transaction as main update, before the main update? If you use "readpast" to pick up PKs eligible for updates you'll never block on it at all.

 

by: jneferPosted on 2009-10-21 at 23:51:07ID: 25631365

Hi Joe,
I fear i have not understood your suggestions to avoid the dererred update. Do you want me to 1) create a holding table and populate the PKs in it 2) use this table to populate my main table? 3) And then delete those PKs that are populated in the main table from the holding table?

if my understanding is correct, would this not increase the run time as i will be introducing a huge insert? also how would i avoid populating duplicate rows in this holding table as well?
i apologize if i had not understood your suggestion correctly. please help me understand. My need is to avoid populating a record that was already inserted and thus eliminate duplicate insertion failures.

Also please note that we had changed the lock schema in the table to "page" lock before this run.

Thanks,
Jennifer

 

by: Joe_WoodhousePosted on 2009-10-21 at 23:59:41ID: 25631406

Without knowing your existing code it's hard to make specific suggestions. How do you know which rows to update currently? If it's a huge update then inserting a whole of PKs will add up, yes. Can you express your condition as anything other than a NOT something? Perhaps show us the existing logic you added for that?

Was that datapages or allpages locking, BTW?

 

by: jneferPosted on 2009-10-22 at 00:30:05ID: 25631547

Hi Joe,
I have attached the code snippet here fyr. lock schema was DATAPAGES. All columns that i added inside the NOT EXISTS conditions are used in unique clustered index.
Please let me know if you need more details.

Thanks,
Jennifer

INSERT INTO claim_extract
 
SELECT
	core.CLAIM_ID                                  ,
	line.SEQ_NO                              ,
	core.CUR_STS                             ,
	line.CUR_STS                             ,
	core.MEME_CK                             ,
	core.SBSB_CK                             ,
	SPACE(9) AS SBSB_ID                           ,
	core.PROV_ID                                  ,
	core.GROUP_ID                                  ,
	SPACE(9) AS TAX_ID                            ,
	SPACE(4) AS PROV_SPEC                     ,
	'N' AS PAR_NPAR                           ,
	core.MEM_AGE                              ,
	core.MEM_SEX                            ,
	5 AS REC_TYPE                             ,
	line.UMAUTH_ID                           ,
	line.REV_ID                                  ,
	line.SERVICE_ID                                  ,
	SPACE(4) AS BILL_TYPE                     ,
	0 AS UPDATE_IND
 
FROM  
	claim_core             core NOHOLDLOCK,
	claim_line_dtl         line,
	#TMP_GRGR_GROUP                     TMPG
WHERE  core.CLAIM_ID = line.CLAIM_ID
AND    core.GROUP_ID = TMPG.GROUP_ID
AND    core.CLCL_PAID_DT BETWEEN @from_dt AND @to_date
AND    NOT EXISTS ( SELECT 1 
                    FROM claim_extract extr
                    WHERE extr.CLAIM_ID = core.CLAIM_ID
		    AND   extr.SEQ_NO = line.CDML_SEQ_NO
		    AND   extr.GRGR_ID = core.GRGR_ID
		    AND   extr.REC_TYPE = 5
		  )

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:

Select allOpen in new window

 

by: Joe_WoodhousePosted on 2009-10-22 at 02:41:30ID: 25632248

Could you batch it one GROUP_ID at a time, and then delete all rows with that GROUP_ID from the temp table?

By the way "noholdlock" doesn't mean what you think it means, that's only relevant to a certain type of cursor from the client side. You're still getting locks there.

 

by: jneferPosted on 2009-10-22 at 02:55:57ID: 25632338

Hi Joe,
During concurrent runs, each instance of the process will handle only one GROUP_ID. This is one of the input parameter to the procedure. Basically we are trying to populate the "claim_extract" table concurrently, each instance populating records belonging to one GROUP. Each GROUP contains more than 200,000 records qualifying the criteria.
Temp table would contain multiple GROUP_IDs only during non-concurrent (single) executions.

Thanks,
Jennifer

 

by: Joe_WoodhousePosted on 2009-10-22 at 03:05:15ID: 25632404

it's a lot easier to make sure you're only inserting the correct rows in the first place rather than fetching rows and only then checking to make sure they aren't ones you've already handled...

Basically put the smarts in the first step of how the underlying work set is built rather than just building it and then checking to see if the rows you've got are the right ones.

Also have a look at the various ignore_dup_key/ignore_dup_row options, you can silently drop duplicate insertions to a table. Sometimes that's the fastest way of handling this sort of issue. :)

 

by: Joe_WoodhousePosted on 2009-10-22 at 03:05:25ID: 25632406

Those options apply to indexes, BTW.

 

by: jneferPosted on 2009-10-23 at 00:25:21ID: 25641971

Hi Joe,
I'm still working on executing my process and simultaneously run the sysmon. I shall keep you updated about the findings soon.
BTW, ignore_dup_key will be helpful to only "delete" the duplicate records records that were already loaded right? It wont avoid populating the duplicate rows in the first place right?

Thanks,
Jennifer

 

by: Joe_WoodhousePosted on 2009-10-24 at 23:59:43ID: 25655763

No, you're thinking of ignore_dup_row, which cleans out existing duplicates (and prevents new ones) - it only works for entire rows though. ignore_dup_key might be helpful here, it rejects inserts that would cause a duplicate key (not row). Possibly I'm just distracting you with this though. :)

 

by: jneferPosted on 2009-10-28 at 20:31:26ID: 25690473

Hi Joe,
We have arrived at a logic similar to the holding table suggestion that you provided and have eliminated the deferred update inserts :)
We are right now executing the process several times to check the runtimes. Following are the changes we are making in the code and DB to achieve good concurrent results.
1) Perform each query in a batch.
2) Table locks changed to datarows
3) use a holding table to avoid deferred updates
4) Increase the no of locks in the adaptive server to a greater extent possible.

as you said HWM thresholds were never changed.
Thank you so much for the excellent suggestions provided. I shall go ahead and accept all solutions that worked for me.
Once again thanks a ton!

Thanks,
Jennifer

 

by: Joe_WoodhousePosted on 2009-10-28 at 21:10:12ID: 25690589

Happy to help, I always enjoy making the database go faster! :)

Good luck!

 

by: jneferPosted on 2009-10-28 at 21:23:29ID: 31641025

Joe Woodhouse is an excellent expert. Would like to ask him any DB suggestions in future as well.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...