如何使用asp.net mvc并行执行5个存储过程 [英] How to execute 5 stored procedures parallel using asp.net mvc

查看:76
本文介绍了如何使用asp.net mvc并行执行5个存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何使用asp.net mvc并行执行5个存储过程。

在我的动作方法中,我需要执行5存储过程,但是每个sp需要2到3秒。

执行完成5 sp后需要10到12秒。我需要并行执行5个sp。

解决方案

参考:



http://softwarecafeblog.blogspot.in/2010/12/making-parallel-database-calls-using。 html [ ^ ]


您应该考虑的第一个问题是这些程序是否依赖于相同的数据并且是要修改的数据。换句话说,程序可以以任何顺序执行而不影响结果吗?



第二个问题是,程序是否仍在修改相同的数据。如果是,你可能很有可能锁定冲突,甚至死锁。



如果上述任何一个问题属实,你可能不应该使用异步调用。



在进入异步模型之前,您应该调查是否可以增强程序的性能。它们是以最佳方式执行的。如果往返花费时间,为什么不创建一个调用这些过程的小程序。这样你只能使用来自客户端的单个调用。



毕竟如果你决定使用异步执行,首先需要打开5个独立的连接,然后对于每个连接,您可以使用 SqlCommand.BeginExecuteNonQuery [< a href =https://msdn.microsoft.com/en-us/library/ca56w9se(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]或 SqlCommand.BeginExecuteNonQuery Method(AsyncCallback,Object) [ ^ ]

Hi,

How to execute 5 stored procedures parallel using asp.net mvc .
In my action method I need execute 5 stored procedures, but each sp take 2 to 3 seconds.
after execution complted 5 sp's it will take 10 to 12 seconds. I need to execute 5 sp's parallelly.

解决方案

Refer this:

http://softwarecafeblog.blogspot.in/2010/12/making-parallel-database-calls-using.html[^]


The first question you should consider is that are these procedures dependent on the same data and is that data being modified. In other words can the procedures be executed in any order without affecting the result?

The second question is, are the procedures still modifying the same data. If they are, you may have a big chance of locking conflicts, even deadlocks.

If the either of the above questions is true, you probably shouldn't be using asynchronous calls.

Also before going to asynchronous model, you should investigate if the performance of the procedures can be enhanced. Are they executed in an optimal way. If the roundtrips are taking the time, why not create a small procedure which calls these procedures. This way you can use only single call from the client side.

And after all if you decide to use asynchronous executions, first you need to open 5 separate connections and then with each connection you can use methods like SqlCommand.BeginExecuteNonQuery[^] or SqlCommand.BeginExecuteNonQuery Method (AsyncCallback, Object)[^]


这篇关于如何使用asp.net mvc并行执行5个存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆