Buffering


Recording Web events takes time, and you might not like the impact this can have on the response time of your Web pages. Providers that derive from BufferedWebEventProvider support buffering (refer back to Figure 7-2), which in essence lets providers record Web events asynchronously by queuing the Web events in memory as they occur and then letting a background thread do the actual recording.

Buffered providers implicitly support two extra attributes in their configuration. The first is "buffer," which specifies whether or not you want to use buffering at all. Note that this attribute is "true" by default on all buffered providers, so you'll need to explicitly add this attribute and set it to "false" if you don't want buffering with, for example, the SQL provider. The second, which must be present if buffering is enabled, is bufferMode. This attribute allows you to choose how big the buffer will be, how often it will be flushed, and so on, by referring to a predefined buffer "mode."

Each buffer mode has six attributes that you can adjust, and as of this writing they aren't documented very clearly. Table 7-1 outlines what we've been able to learn about them by studying the code in BufferedWebEventProvider.

Table 7-1. Buffer mode attributes

Attribute

Description

maxBufferSize

This is the maximum size of the queue. If an event is added and the queue is already at its maximum size, the oldest event in the queue will be discarded to make room for the new event, and a counter of lost events will be incremented.

maxFlushSize

This is the maximum number of events that will be flushed at one time.

regularFlushInterval

This is the amount of time (in milliseconds) that should normally occur between flushes. If set to "Infinite," flushes will only occur based on the size of the queue using "urgent" flushes.

urgentFlushThreshold

When the number of events in the queue reaches this number, the regular flush interval will be temporarily reduced to the urgentFlushInterval value. That is, the queue will be flushed more often when above this threshold. This must be a smaller value than maxBufferSize.

urgentFlushInterval

This is the number of milliseconds between scheduled flushes when the queue reaches the urgentFlushThreshold. This must be a smaller value than regularFlushInterval.

maxBufferThreads

This is the maximum number of background threads allowed to simultaneously flush. This is set to 1 for all default buffer modes, which makes us wonder if any of the built-in providers actually support multithreaded flushes.


There are several of these modes defined in the root web.config file, and you can define others by adding a <bufferModes> section to your application's web.config file. Table 7-2 will help you learn the built-in modes and how they differ.

Table 7-2. Built-in buffer modes

Name

maxBufferSize

Comments

Critical Notification

100

Flushed every minute.

Notification

300

Flushed every minute.

Analysis

1,000

Normally flushed every 5 minutes, unless there are 100 or more queued events, in which case the flush interval reduces to 1 minute.

Logging

1,000

Normally flushed every 30 minutes, unless there are 800 or more queued events, in which case the flush interval reduces to 5 minutes.


While it might be tempting to use a more aggressive buffering scheme (such as Logging), you need to consider that when your worker process crashes, you'll lose any buffered messages that haven't yet been flushed to a persistent media. So even if you're only planning on using SqlWebEventProvider, you might actually create two entries in the <providers> element under the <healthMonitoring> section in web.config and choose different buffering strategies, as shown in Listing 7-5 (this example also shows how to log to different databases). You could then register the nonbuffered provider for important events that you can't afford to lose, and the buffered provider for events you're just tracking for statistical analysis.

Listing 7-5. Configuring buffering for the SQL provider

<!-- web.config --> <healthMonitoring enabled="true">   <providers>     <add name="SecuritySqlProvider"          type="System.Web.Management.SqlWebEventProvider"          connectionStringName="securityDatabase"          buffer="false"/>     <add name="StatisticsSqlProvider"          type="System.Web.Management.SqlWebEventProvider"          connectionStringName="statisticsDatabase"          buffer="true"          bufferMode="Logging"/>   </providers>   <!-- ... --> </healthMonitoring> 




Essential ASP. NET 2.0
Essential ASP.NET 2.0
ISBN: 0321237706
EAN: 2147483647
Year: 2006
Pages: 104

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