public void Process()
        {
            try
            {
                if (_parent != null && _parent._cache.AsyncEventHandler != null)
                {
                    _stats = new UsageStats();
                    _stats.BeginSample();
                    _parent._cache.EventListener.OnCustomUpdateCallback(_callBackId, _key, _notifyAsync, _item, _oldItem, _flag,_dataFilter);

                    _stats.EndSample();
                    _parent._perfStatsColl2.IncrementAvgEventProcessingSample(_stats.Current);
                }
            }
            catch (Exception ex)
            {
                if (_parent.Logger.IsErrorLogsEnabled) _parent.Logger.NCacheLog.Error("Item Updated Callback Task.Process", ex.ToString());
            }
        }
Example #2
0
		/// <summary>
		/// Initializes the counter instances and category.
		/// </summary>
        public void InitializePerfCounters(bool inproc)
		{
            try
            {
                if (!UserHasAccessRights)
                    return;

                lock (this)
                {
                    int ncounter = 1;
                    string instname = _instanceName;

                    if (inproc)
                    {
                        int processid = Process.GetCurrentProcess().Id;
                        while (PerformanceCounterCategory.InstanceExists(instname, PC_CATEGORY))
                        {
                            instname = _instanceName + ":" + ncounter.ToString() + " - " + processid.ToString() + _port;
                            ncounter++;
                        }
                        _instanceName = instname;
                    }

                    _pcCount = new PerformanceCounter(PC_CATEGORY, "Count", _instanceName, false);
                    _pcCachelastAccessCount = new PerformanceCounter(PC_CATEGORY, "CacheLastAccessCount", _instanceName, false);
                    _pcHitsPerSec = new PerformanceCounter(PC_CATEGORY, "Hits/sec", _instanceName, false);
                    _pcMissPerSec = new PerformanceCounter(PC_CATEGORY, "Misses/sec", _instanceName, false);
                    _pcHitsRatioSec = new PerformanceCounter(PC_CATEGORY, "Hits ratio/sec (%)", _instanceName, false);
                    _pcHitsRatioSecBase = new PerformanceCounter(PC_CATEGORY, "Hits ratio/sec base", _instanceName, false);
                    _pcAddPerSec = new PerformanceCounter(PC_CATEGORY, "Additions/sec", _instanceName, false);
                    _pcGetPerSec = new PerformanceCounter(PC_CATEGORY, "Fetches/sec", _instanceName, false);
                    _pcUpdPerSec = new PerformanceCounter(PC_CATEGORY, "Updates/sec", _instanceName, false);
                    _pcDelPerSec = new PerformanceCounter(PC_CATEGORY, "Deletes/sec", _instanceName, false);
                    _pcEvictPerSec = new PerformanceCounter(PC_CATEGORY, "Evictions/sec", _instanceName, false);
                    _pcExpiryPerSec = new PerformanceCounter(PC_CATEGORY, "Expirations/sec", _instanceName, false);

                    _pcCacheSize = new PerformanceCounter(PC_CATEGORY, "Cache Size", _instanceName, false);
                    _pcQueryIndexSize = new PerformanceCounter(PC_CATEGORY, "Query Index Size", _instanceName, false);
                    _pcEvictionIndexSize = new PerformanceCounter(PC_CATEGORY, "Eviction Index Size", _instanceName, false);
                    _pcExpirationIndexSize = new PerformanceCounter(PC_CATEGORY, "Expiration Index Size", _instanceName, false);                    
                    _pcQueryPerSec = new PerformanceCounter(PC_CATEGORY, "Queries/sec", _instanceName, false);
                    _pcAvgQueryExecutionTime = new PerformanceCounter(PC_CATEGORY, "Average µs/Query Execution", _instanceName, false);
                    _pcAvgQueryExecutionTimeBase = new PerformanceCounter(PC_CATEGORY, "Average µs/Query Execution base", _instanceName, false);
                    _usMsecPerQueryExecution = new UsageStats();
                    _pcAvgQuerySize = new PerformanceCounter(PC_CATEGORY, "Average Query Size", _instanceName, false);
                    _pcAvgQuerySizeBase = new PerformanceCounter(PC_CATEGORY, "Average Query Size base", _instanceName, false);                                     

                    _pcMsecPerGetAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/fetch", _instanceName, false);
                    _pcMsecPerGetBase = new PerformanceCounter(PC_CATEGORY, "Average µs/fetch base", _instanceName, false);
                    _usMsecPerGet = new UsageStats();
                    _pcMsecPerAddAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/add", _instanceName, false);
                    _pcMsecPerAddBase = new PerformanceCounter(PC_CATEGORY, "Average µs/add base", _instanceName, false);
                    _usMsecPerAdd = new UsageStats();
                    _pcMsecPerUpdAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/insert", _instanceName, false);
                    _pcMsecPerUpdBase = new PerformanceCounter(PC_CATEGORY, "Average µs/insert base", _instanceName, false);
                    _usMsecPerUpd = new UsageStats();
                    _pcMsecPerDelAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/remove", _instanceName, false);
                    _pcMsecPerDelBase = new PerformanceCounter(PC_CATEGORY, "Average µss/remove base", _instanceName, false);
                    _usMsecPerDel = new UsageStats();
                    _pcStateTxfrPerSec = new PerformanceCounter(PC_CATEGORY, "State transfer/sec", _instanceName, false);
                    _pcMirrorQueueSize = new PerformanceCounter(PC_CATEGORY, "Mirror queue size", _instanceName, false);
                    _pcSlidingIndexQueueSize = new PerformanceCounter(PC_CATEGORY, "Sliding Index queue size", _instanceName, false);
                    _pcDataBalPerSec = new PerformanceCounter(PC_CATEGORY, "Data balance/sec", _instanceName, false);

                    _usMsecPerDel = new UsageStats();
                }
            }
            catch (Exception e)
            {
                NCacheLog.Error("PerfStatsCollector.PerfStatsCollector()", e.Message);
            }

		}
Example #3
0
        internal virtual object SafeSerialize(object serializableObject, string serializationContext, ref BitSet flag, ref long size)
        {
            object serializedObject = null;

            if (_cacheImpl == null)
                throw new OperationFailedException("Cache is not initialized");

            if (serializableObject != null)
            {
                UsageStats statsSerialization = new UsageStats();
                statsSerialization.BeginSample();
                serializedObject = _cacheImpl.SafeSerialize(serializableObject, serializationContext, ref flag, _cacheImpl, ref size);
                statsSerialization.EndSample();
                if (_perfStatsCollector != null)
                    _perfStatsCollector.IncrementMsecPerSerialization(statsSerialization.Current);
            }

            return serializedObject;
        }
Example #4
0
        internal virtual object Remove(string key, LockHandle lockHandle, LockAccessType accessType)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");

            if (key == null) throw new ArgumentNullException("key");
            if (key == string.Empty) throw new ArgumentException("key cannot be empty string");
            long objectSize = 0;

            try
            {
                UsageStats stats = new UsageStats();
                stats.BeginSample();
                object lockId = (lockHandle == null) ? null : lockHandle.LockId;
                BitSet flagMap = new BitSet();
                short dsItemRemovedCallbackId = -1;

                CompressedValueEntry result = _cacheImpl.Remove(key, flagMap, lockId,  accessType);
                if (result != null && result.Value != null)
                {
                    if (result.Value != null && result.Value is CallbackEntry)
                    {
                        result.Value = ((CallbackEntry)result.Value).Value;
                    }
                    if (DebugAPIConfiguraions.LoggingEnabled)
                        objectSize = result.Value is byte[] ? ((byte[])result.Value).Length : 0;
                    result.Value = SafeDeserialize(result.Value, _serializationContext, result.Flag);
                    if (_perfStatsCollector != null)
                    {
                        stats.EndSample();
                        _perfStatsCollector.IncrementMsecPerDelSample(stats.Current);
                        _perfStatsCollector.IncrementDelPerSecStats();
                    }
                    if (DebugAPIConfiguraions.LoggingEnabled)
                        LogSizeInfo(false, objectSize);
                    return result.Value;
                }
                else
                {
                    if (_perfStatsCollector != null)
                    {
                        stats.EndSample();
                        _perfStatsCollector.IncrementMsecPerDelSample(stats.Current);
                        _perfStatsCollector.IncrementDelPerSecStats();
                    }
                }

            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
            }
            return null;
        }
Example #5
0
        /// <summary>
        /// Function that choose the appropriate function of NCache's Cache, that need to be called
        /// according to the data provided to it.</summary>
        internal virtual void InsertOperation(string key, object value, DateTime absoluteExpiration,
            TimeSpan slidingExpiration, CacheItemPriority priority,
            LockHandle lockHandle, LockAccessType accessType, CacheDataNotificationCallback cacheItemUdpatedCallback,
            CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, ref long size, bool allowQueryTags)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");

            ValidateKeyValue(key, value);
            UsageStats stats = new UsageStats();
            stats.BeginSample();
            Hashtable queryInfo = new Hashtable();
            object lockId = (lockHandle == null) ? null : lockHandle.LockId;

            if (allowQueryTags)
            {
                queryInfo["query-info"] = GetQueryInfo(value);
            }
            short removeCallbackId = -1;
            short updateCallbackId = -1;
            short dsItemUpdateCallbackId = -1;

            BitSet flagMap = new BitSet();
            try
            {
                value = SafeSerialize(value, _serializationContext, ref flagMap, ref size);

                long objectSize = 0;
                if (DebugAPIConfiguraions.LoggingEnabled)
                    objectSize = value is byte[] ? ((byte[])value).Length : 0;
                if (_perfStatsCollector != null && value != null && value is byte[])
                    _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length);

                if (cacheItemRemovedCallaback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemRemovedCallaback, EventType.ItemRemoved, itemRemovedDataFilter);
                    removeCallbackId = callabackIds[1];
                }

                if (cacheItemUdpatedCallback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemUdpatedCallback, EventType.ItemUpdated, itemUpdateDataFilter);
                    updateCallbackId = callabackIds[0];
                }

                if (lockId != null && ((string)lockId) != string.Empty)
                    flagMap.SetBit(BitSetConstants.LockedItem);
                else
                    flagMap.UnsetBit(BitSetConstants.LockedItem);

                absoluteExpiration = ToUTC(absoluteExpiration);

                _cacheImpl.Insert(key, value, absoluteExpiration, slidingExpiration, priority, removeCallbackId, updateCallbackId, queryInfo, flagMap, lockId, accessType, itemUpdateDataFilter, itemRemovedDataFilter, size);

                if (_perfStatsCollector != null)
                {
                    stats.EndSample();
                    _perfStatsCollector.IncrementMsecPerUpdSample(stats.Current);
                    _perfStatsCollector.IncrementUpdPerSecStats();
                }
            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
            }
        }
Example #6
0
        internal virtual object GetInternal(string key,  LockAccessType accessType, TimeSpan lockTimeout, ref LockHandle lockHandle)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");

            if (key == null) throw new ArgumentNullException("key");
            if (key == string.Empty) throw new ArgumentException("key cannot be empty string");
            long objectSize = 0;

            CompressedValueEntry result = null;
            try
            {
                BitSet flagMap = new BitSet();
                UsageStats stats = new UsageStats();
                stats.BeginSample();
                result = _cacheImpl.Get(key, flagMap, ref lockHandle, lockTimeout, accessType);
                if (_perfStatsCollector != null)
                {
                    stats.EndSample();
                    _perfStatsCollector.IncrementMsecPerGetSample(stats.Current);
                    _perfStatsCollector.IncrementGetPerSecStats();
                }
                if (result != null && result.Value != null)
                {
                    if (result.Value is CallbackEntry)
                    {
                        CallbackEntry e = result.Value as CallbackEntry;
                        result.Value = e.Value;
                    }
                    if (DebugAPIConfiguraions.LoggingEnabled)
                        objectSize = result.Value is byte[] ? ((byte[])result.Value).Length : 0;

                    result.Value = SafeDeserialize(result.Value, _serializationContext, result.Flag);
                    if (DebugAPIConfiguraions.LoggingEnabled)
                        LogSizeInfo(false, objectSize);
                    return result.Value;
                }
            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
                else return null;
            }
            return null;
        }
Example #7
0
        internal virtual void Delete(string key, LockHandle lockHandle,  LockAccessType accessType)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");

            if (key == null) throw new ArgumentNullException("key");
            if (key == string.Empty) throw new ArgumentException("key cannot be empty string");
            try
            {
                UsageStats stats = new UsageStats();
                stats.BeginSample();
                object lockId = (lockHandle == null) ? null : lockHandle.LockId;
                BitSet flagMap = new BitSet();

                _cacheImpl.Delete(key, flagMap, lockId, accessType);
            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
            }
        }
Example #8
0
        /// <summary>
        /// Function that choose the appropriate function of NCache's Cache, that need to be called
        /// according to the data provided to it.</summary>
        internal virtual object AddOperation(string key, object value, DateTime absoluteExpiration,
            TimeSpan slidingExpiration, CacheItemPriority priority, 
            
            CacheDataNotificationCallback cacheItemUdpatedCallback, CacheDataNotificationCallback cacheItemRemovedCallaback,
            EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, ref long size, bool allowQueryTags)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");
            ValidateKeyValue(key, value);
            UsageStats stats = new UsageStats();
            stats.BeginSample();

            Hashtable queryInfo = new Hashtable();
            if (allowQueryTags)
            {
                queryInfo["query-info"] = GetQueryInfo(value);
            }
            BitSet flagMap = new BitSet();
            try
            {
                long objectSize = 0;
                value = SafeSerialize(value, _serializationContext, ref flagMap, ref size);

                if (DebugAPIConfiguraions.LoggingEnabled)
                    objectSize = value is byte[] ? ((byte[])value).Length : 0;
                if (_perfStatsCollector != null && value != null && value is byte[])
                    _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length);
                if (DebugAPIConfiguraions.LoggingEnabled)
                {
                    LogSizeInfo(false, objectSize);
                }

                short removeCallbackID = -1;
                short updateCallbackID = -1;
                if (cacheItemRemovedCallaback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemRemovedCallaback, EventType.ItemRemoved, itemRemovedDataFilter);
                    removeCallbackID = callabackIds[1];
                }

                if (cacheItemUdpatedCallback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemUdpatedCallback, EventType.ItemUpdated, itemUpdateDataFilter);
                    updateCallbackID = callabackIds[0];
                }

                absoluteExpiration = ToUTC(absoluteExpiration);

                _cacheImpl.Add(key, value, absoluteExpiration, slidingExpiration, priority, removeCallbackID, updateCallbackID, queryInfo, flagMap, itemUpdateDataFilter, itemRemovedDataFilter, size);

                if (_perfStatsCollector != null)
                {
                    stats.EndSample();
                    _perfStatsCollector.IncrementMsecPerAddSample(stats.Current);
                    _perfStatsCollector.IncrementAddPerSecStats();
                }
                return value;
            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
            }
            return null;
        }
Example #9
0
        /// <summary>
        /// Initializes the counter instances and category.
        /// </summary>
        public void InitializePerfCounters()
        {
            try
            {
                if (!UserHasAccessRights)
                    return;

                lock (this)
                {
                    _pcRequestsPerSec = new PerformanceCounter(PC_CATEGORY, "Requests/sec", _instanceName, false);
                    _pcResponsesPerSec = new PerformanceCounter(PC_CATEGORY, "Responses/sec", _instanceName, false);
                    _pcClientBytesSentPerSec = new PerformanceCounter(PC_CATEGORY, "Client bytes sent/sec", _instanceName, false);
                    _pcClientBytesReceiedPerSec = new PerformanceCounter(PC_CATEGORY, "Client bytes received/sec", _instanceName, false);

                    _pcMsecPerCacheOperation = new PerformanceCounter(PC_CATEGORY, "Average �s/cache operation", _instanceName, false);
                    _pcMsecPerCacheOperationBase = new PerformanceCounter(PC_CATEGORY, "Average �s/cache operation base", _instanceName, false);

                    _usMsecPerCacheOperation = new UsageStats();
                    _nsMsecPerCacheOperation = new NanoSecTimeStats();

                    _generalNotificationQueueSize = new PerformanceCounter(PC_CATEGORY, "General Notifications Queue Size", _instanceName, false);
                    _pcResponseQueueCount = new PerformanceCounter(PC_CATEGORY, "Response Queue Count", _instanceName, false);
                    _pcResponseQueueSize = new PerformanceCounter(PC_CATEGORY, "Response Queue Size", _instanceName, false);
                    _pcEventQueueCount = new PerformanceCounter(PC_CATEGORY, "Event Queue Count", _instanceName, false);

                }
            }
            catch (Exception e)
            {
                AppUtil.LogEvent("NCache", "An error occurred while initializing counters for NCache Server. " + e.ToString(), EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError);
            }
        }
Example #10
0
        /// <summary>
        /// Initializes the counter instances and category.
        /// </summary>
        public void InitializePerfCounters(bool inproc)
        {
            try
            {
                if (!UserHasAccessRights)
                    return;

                lock (this)
                {
                    int ncounter = 1;
                    string instname = _instanceName;

                    _pcAddPerSec = new PerformanceCounter(PC_CATEGORY, "Additions/sec", _instanceName, false);
                    _pcGetPerSec = new PerformanceCounter(PC_CATEGORY, "Fetches/sec", _instanceName, false);
                    _pcUpdPerSec = new PerformanceCounter(PC_CATEGORY, "Updates/sec", _instanceName, false);
                    _pcDelPerSec = new PerformanceCounter(PC_CATEGORY, "Deletes/sec", _instanceName, false);

                    _pcEventTriggeredPerSec = new PerformanceCounter(PC_CATEGORY, "Events Triggered/sec", _instanceName, false);
                    _pcEventProcesedPerSec = new PerformanceCounter(PC_CATEGORY, "Events Proccesed/sec", _instanceName, false);

                    _pcMsecPerGetAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/fetch", _instanceName, false);
                    _pcMsecPerGetBase = new PerformanceCounter(PC_CATEGORY, "Average µs/fetch base", _instanceName, false);
                    _usMsecPerGet = new UsageStats();
                    _pcMsecPerAddAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/add", _instanceName, false);
                    _pcMsecPerAddBase = new PerformanceCounter(PC_CATEGORY, "Average µs/add base", _instanceName, false);
                    _usMsecPerAdd = new UsageStats();
                    _pcMsecPerUpdAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/insert", _instanceName, false);
                    _pcMsecPerUpdBase = new PerformanceCounter(PC_CATEGORY, "Average µs/insert base", _instanceName, false);
                    _usMsecPerUpd = new UsageStats();
                    _pcMsecPerDelAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/remove", _instanceName, false);
                    _pcMsecPerDelBase = new PerformanceCounter(PC_CATEGORY, "Average µs/remove base", _instanceName, false);
                    _usMsecPerDel = new UsageStats();

                    _pcReqrQueueSize = new PerformanceCounter(PC_CATEGORY, "Request queue size", _instanceName, false);

                    _pcMsecPerEventAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/event", _instanceName, false);
                    _pcMsecPerEventBase = new PerformanceCounter(PC_CATEGORY, "Average µs/event base", _instanceName, false);
                    _usMsecPerEvent = new UsageStats();

                    _usMsecPerDel = new UsageStats();

                    _pcMsecPerSerializationAvg = new PerformanceCounter(PC_CATEGORY, "Average µs/serialization", _instanceName, false);
                    _pcMsecPerSerializationAvgBase = new PerformanceCounter(PC_CATEGORY, "Average µs/serialization base", _instanceName, false);

                }
            }
            catch (Exception e)
            {
            }
        }