任务并行库与外部SQL Server

I have a Windows Service which executes large number of tasks in parallel using the Task Parallel Library (TPL). This is about to be extended to handle tasks which interact with an SQL Server on an external server.

TPL is supposed to be good at measuring load and assigning the right number of parallel threads to the tasks. Is there a way to make it aware of load to the external SQL Server instance? The actual code to run for each task on the local server is quite small, but the calls to the database can be quite heavy.

Am I not likely to end up with my service bogging down the database with request because TPL sees that the local server has loads of free resources, or is there a known way to handle this?

#0

There's is nothing native to TPL that will help you with this. TPL is about managing/maximizing the CPU load of your local application. It has no idea about SQL load, let alone on another machine.

That said, if you wanted to get crazy, there is an extensibility point called the TaskScheduler. You could theoretically implement a custom TaskScheduler that can watch the load on the SQL server and only schedule tasks to execute if that load is at some defined threshold.

Honestly though, I don't think it's the right solution to the problem. Managing load against a shared resource like a SQL server is a completely different beast than what TPL is designed to solve. You'd be much better off just making sure you design your application such that it doesn't abuse the SQL server in its own right by load testing, finding a sweet spot and configuring your application not go out outside those bounds. From there it would be up to your DBA to determine the right solution for the SQL server infrastructure itself to manage that application's needs along with any other external load.

#1

If you parallelise the data access functionality in your client application, you will find that the next bottleneck is the SQL Server connection pool.

推荐文章

一种自动分离C++报头的工具及其实现

一种自动分离C++报头的工具及其实现

推荐文章

使用boost::gregorian::from\u string()时出现链接器错误

使用boost::gregorian::from\u string()时出现链接器错误

推荐文章

Rails3设计“每个客户端的令牌”

Rails3设计“每个客户端的令牌”

推荐文章

问题似乎不是先问PHP

问题似乎不是先问PHP

推荐文章

Maven依赖特定类

Maven依赖特定类

推荐文章

带有JMDN的示例

带有JMDN的示例

推荐文章

我应该担心这个。。。?

我应该担心这个。。。?

推荐文章

如何删除字符串中一个字符后的所有字符?

如何删除字符串中一个字符后的所有字符?

推荐文章

Prism CompositePresentationEvent开火两次

Prism CompositePresentationEvent开火两次

推荐文章

Z-索引或层顺序

Z-索引或层顺序

推荐文章

使用NSURLConnection执行不同的请求是否可以使会话保持活动状态?

使用NSURLConnection执行不同的请求是否可以使会话保持活动状态?

推荐文章

PostgreSQL选择日期查询

PostgreSQL选择日期查询

推荐文章

邮件()不工作,有什么想法吗?

邮件()不工作,有什么想法吗?

推荐文章

根据缩略图更改SurfaceView图像

根据缩略图更改SurfaceView图像

推荐文章

如何在cocos2d iPhone中录制游戏

如何在cocos2d iPhone中录制游戏

推荐文章

在filtertoolbar上设置默认值

在filtertoolbar上设置默认值