线程在CLR在SQL Server 2008线程、CLR、SQL、Server

由网友(惟有时光忆年少ˉ)分享简介:我有一个 CLR 的过程,在运行SQL Server2008的。它建立几个表中的数据缓存在一个静态类后来被其他调用持有使用。I have a CLR process which runs under SQL Server2008. It builds a cache of several tables data to...

我有一个 CLR 的过程,在运行SQL Server2008的。它建立几个表中的数据缓存在一个静态类后来被其他调用持有使用。

I have a CLR process which runs under SQL Server2008. It builds a cache of several tables data to hold in a static class for use later by other calls.

我的问题是我能提高加载的过程中这种缓存通过生成线程加载每个数据集/表缓存?

My question is could I improve the process of loading this cache by spawning threads to load each data set/ table in my cache?

我steared清楚这在过去的各个岗位都建议离开线程管理,以 SQL服务器。不过,我真的可以做加速这一过程。 目前,它的一个连续过程来加载每个数据集。如果我能运行这些兼任这将是非常方便的。一个过程中,我已经做了很多的atime的 CLR 罩外得到一些额外的性能提升。

I've steared clear of this in the past as various posts have suggested leave the thread management to SQL Server. However I could really do with speeding up this process. Currently its a sequential process to load each data set. If I could run these concurrently it would be very handy. A process I've done many atime outside of the CLR cover to get some extra performance gains.

任何想法帮助技巧非常AP preciated。

Any ideas help tips very much appreciated.

推荐答案

您可以使用线程,但他们必须表现。否则你会失去利用他们的优势。

You can use threads, but they must behave. Otherwise you'll lose the benefits of using them.

从的CLR宿主环境

如何SQL Server和CLR一起工作

本节讨论了SQL Server的集成线程,   SQL的调度,同步,和存储器管理模式   服务器和CLR。特别是,这部分检查   集成方法的可扩展性,可靠性和安全性的目标。   SQL Server的实质上充当操作系统为CLR时   它位于SQL Server内部。 CLR的调用低级例程   由SQL Server的线程,调度,同步实施,   和内存管理。这些是相同的原语的其余部分   SQL Server引擎使用。这种方法提供了几个   可扩展性,可靠性和安全性的好处。

This section discusses how SQL Server integrates the threading, scheduling, synchronization, and memory management models of SQL Server and the CLR. In particular, this section examines the integration in light of scalability, reliability, and security goals. SQL Server essentially acts as the operating system for the CLR when it is hosted inside SQL Server. The CLR calls low-level routines implemented by SQL Server for threading, scheduling, synchronization, and memory management. These are the same primitives that the rest of the SQL Server engine uses. This approach provides several scalability, reliability, and security benefits.

可扩展性:常见的线程,调度和同步

Scalability: Common threading, scheduling, and synchronization

CLR来创建线程调用SQL服务器API,无论是对正在运行的用户   code和供自己内部使用。为了之间的同步   多线程,则CLR调用SQL Server的同步对象。   这使得SQL Server调度安排其他任务时,   线程正在等待同步对象。例如,当   CLR启动垃圾收集,它的所有线程等待垃圾   收集完成。因为CLR线程和所述同步   他们正在等待的对象是已知的SQL Server计划,SQL   服务器可以安排其他正在运行的数据库任务不是线程   涉及CLR。这也使SQL Server检测死锁   涉及采取的CLR同步对象,并采用锁   传统的技术僵局去除。

CLR calls SQL Server APIs for creating threads, both for running user code and for its own internal use. In order to synchronize between multiple threads, the CLR calls SQL Server synchronization objects. This allows the SQL Server scheduler to schedule other tasks when a thread is waiting on a synchronization object. For example, when the CLR initiates garbage collection, all of its threads wait for garbage collection to finish. Because the CLR threads and the synchronization objects they are waiting on are known to the SQL Server scheduler, SQL Server can schedule threads that are running other database tasks not involving the CLR. This also enables SQL Server to detect deadlocks that involve locks taken by CLR synchronization objects and employ traditional techniques for deadlock removal.

管理code运行preemptively在SQL Server中。在SQL Server调度   具有及时发现并制止,但没有得到一个线程的能力   显著的时间量。勾CLR线程SQL的能力   服务器线程意味着SQL Server调度程序能够识别   在CLR失控线程和管理他们的优先级。这种失控   线程被挂起,并放回到队列中。线程是   反复确认为离家出走的线程不允许运行的   给定一段时间,以便其他执行人员可以运行。

Managed code runs preemptively in SQL Server. The SQL Server scheduler has the ability to detect and stop threads that have not yielded for a significant amount of time. The ability to hook CLR threads to SQL Server threads implies that the SQL Server scheduler can identify "runaway" threads in the CLR and manage their priority. Such runaway threads are suspended and put back in the queue. Threads that are repeatedly identified as runaway threads are not allowed to run for a given period of time so that other executing workers can run.

阅读全文

相关推荐

最新文章