Click or drag to resize

FastThreadLocalT Class

IThreadLocal provides the engine with a way to store information that is local to the instance and a the thread. While the CLR provides the ThreadStatic attribute, it can only be applied to static variables; some usage patterns in esper (such as statement-specific thread-specific processing data) require that data be associated by instance and thread. The CLR provides a solution to this known as LocalDataStoreSlot. It has been documented that this method is slower than its ThreadStatic counterpart, but it allows for instance-based allocation.

During recent testing it was determined that the LocalDataStoreSlot was using an amount of time that seemed a bit excessive. We took some snapshots of performance under the profiler. Using that information we retooled the class to provide tight and fast access to thread-local instance-specific data. The class is pretty tightly wound and takes a few liberties in understanding how esper uses it. A ThreadStatic variable is initialized for the IThreadLocal. This item is 'thread-local' and contains an array of 'instance-specific' data. Indexing is done when the IThreadLocal item is created. Under esper this results in roughly one 'index' per statement. Changes to this model resulted in good cost savings in the retrieval and acquisition of local data.

Inheritance Hierarchy
SystemObject
  com.espertech.esper.compat.threading.threadlocalFastThreadLocalT

Namespace:  com.espertech.esper.compat.threading.threadlocal
Assembly:  NEsper.Compat (in NEsper.Compat.dll) Version: 8.0.0.0
Syntax
C#
public sealed class FastThreadLocal<T> : IThreadLocal<T>, 
	IDisposable

Type Parameters

T

[Missing <typeparam name="T"/> documentation for "T:com.espertech.esper.compat.threading.threadlocal.FastThreadLocal`1"]

The FastThreadLocalT type exposes the following members.

Constructors
  NameDescription
Public methodFastThreadLocalT
Initializes a new instance of the FastThreadLocalT class
Top
Properties
  NameDescription
Public propertyInstanceId
Gets the instance id ... if you really must know.
Public propertyValue
Gets or sets the value.
Top
Methods
  NameDescription
Public methodClearAll
Clears all threads
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Public methodGetOrCreate
Gets the data or creates it if not found.
Public methodRemove
Resets the thread local instance.
Top
See Also