Chapter 14. Integrating the CLR with Custom Schedulers and Thread Pools


In Chapter 13, I describe how hosting the CLR within Microsoft SQL Server 2005 requires the CLR hosting API to act as an abstraction layer through which the CLR directs all requests to allocate and free memory. In this chapter, I show how the same approach has been taken to enable SQL Server 2005 to supply the basic primitives needed by the CLR to create and manage tasks, manipulate synchronization primitives, and queue work items to a thread pool. The managers that implement these abstractions are the task, synchronization, and thread pool managers.

Integrating how the CLR works with tasks, synchronization primitives, and the thread pool is required to meet the performance and scalability requirements of SQL Server 2005. One scenario of particular interest is a mode of execution termed fiber mode. In fiber mode, SQL Server uses cooperatively scheduled fibers to achieve high throughput on multiprocessor machines. These fibers are managed by the SQL Server custom scheduler and can be moved freely between threads to get the maximum amount of work done given the number of currently available threads. The ability to run in an environment where tasks are scheduled cooperatively is completely new to the CLR. In both Microsoft .NET Framework version 1.0 and .NET Framework version 1.1, the CLR assumed it was running in an environment in which code was preemptively scheduled directly by the operating system. As you'll see, one of the primary capabilities of the task manager is to enable the host to insulate the CLR from the knowledge of whether the underlying scheduling mechanism is preemptive or cooperative.

Without a doubt, the interaction between the host and the CLR through the task and synchronization managers is much more complex than with any other hosting interfaces I've described in this book. In effect, the use of these two managers enables you to control, at a very basic level, how managed code is executed in your process. Several intricacies involved are hard to get right, especially in a way that maintains acceptable performance. In this chapter, I provide an overview of the capabilities that are available by introducing the basic concepts and the interfaces involved. If you choose to take advantage of some of these capabilities in your application, you'll likely find the CoopFiber sample in the .NET Framework version 2.0 SDK very helpful. CoopFiber is a CLR host that uses the task and synchronization managers to implement a managed-code fiber library. Even if you don't need to make use of the hosting managers described in this chapter, understanding their capabilities provides great insight into how the CLR is implemented internally.



    Customizing the Microsoft  .NET Framework Common Language Runtime
    Customizing the Microsoft .NET Framework Common Language Runtime
    ISBN: 735619883
    EAN: N/A
    Year: 2005
    Pages: 119

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net