Beispiel #1
0
        internal Database(IICDbType dbType, string connectionString)
        {
            _configItem                  = new IICDbConfigItem();
            _configItem.DbType           = dbType;
            _configItem.ConnectionString = connectionString;

            _tracing      = TracingManager.GetTracing("Database.[ConnStr=" + connectionString + "]");
            _perfCounters = IICPerformanceCounterFactory.GetCounters <DatabasePerfCounters>(".");

            switch (_configItem.DbType)
            {
            case IICDbType.SqlServer2005:
                _operation = new SqlServerDatabase(_configItem.ConnectionString, 120);
                break;

            case IICDbType.Mysql:
                _operation = new MysqlDatabase(_configItem.ConnectionString, 120);
                break;

            case IICDbType.MysqlBatchInsert:
                _operation = new MysqlBatchInsert(_configItem.ConnectionString);
                break;

            default:
                throw new NotSupportedException(string.Format("Not Support DbType:{0} {1}", _configItem.DbType, _configItem.Name));
            }
        }
Beispiel #2
0
        public RpcServiceDecorator(T serviceObj) : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            p_serviceName = serviceAttr.ServiceName;
            _serviceObj   = serviceObj;

            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                RpcServiceMethodAttribute methodAttr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method);
                string methodName = method.Name;

                RpcServiceMethod m = new RpcServiceDecorator <T> .RpcServiceMethod();

                m.RatePerSecond = category.CreateCounter(methodName + " /sec.", PerformanceCounterType.RateOfCountsPerSecond32);
                m.TotalCount    = category.CreateCounter(methodName + " Total.", PerformanceCounterType.NumberOfItems32);
                m.TotalFailed   = category.CreateCounter(methodName + " Failed.", PerformanceCounterType.NumberOfItems32);
                m.Concurrent    = category.CreateCounter(methodName + " Concurrent.", PerformanceCounterType.NumberOfItems32);
                m.Method        = method;

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
Beispiel #3
0
        public RpcServiceDecorator(T serviceObj, string serviceName) : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            if (!string.IsNullOrEmpty(serviceName))
            {
                p_serviceName = serviceName;
            }
            else
            {
                p_serviceName = serviceAttr.ServiceName;
            }

            _serviceObj = serviceObj;
            _methods    = new HybridDictionary <string, RpcServiceMethod>();

            bool enableCounter = serviceAttr.EnableCounters == RpcPerformanceCounterMode.Both || serviceAttr.EnableCounters == RpcPerformanceCounterMode.Server;

            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                string           methodName = method.Name;
                RpcServiceMethod m;

                RpcServiceBatchMethodAttribute battr = AttributeHelper.TryGetAttribute <RpcServiceBatchMethodAttribute>(method);
                if (battr != null)
                {
                    if (!string.IsNullOrEmpty(battr.MethodName))
                    {
                        methodName = battr.MethodName;
                    }

                    m = new RpcServiceBatchMethod(serviceObj, category, methodName, method, enableCounter);
                }
                else
                {
                    RpcServiceMethodAttribute attr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method);
                    if (!string.IsNullOrEmpty(attr.MethodName))
                    {
                        methodName = attr.MethodName;
                    }

                    m = new RpcServiceMethod(serviceObj, category, methodName, method, enableCounter);
                }

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
Beispiel #4
0
        internal Database(string configKey)
        {
            _configKey    = configKey;
            _tracing      = TracingManager.GetTracing("Database." + configKey);
            _perfCounters = IICPerformanceCounterFactory.GetCounters <DatabasePerfCounters>(configKey);

            try {
                GetInnerOperation();
            } catch (Exception ex) {
                SystemLog.Error(LogEventID.DatabaseFailed, ex, "Database GetFailed <{0}>", configKey);
            }
        }
Beispiel #5
0
        public LRUCacheManager(string name, int cacheCount)
        {
            if (!Stopwatch.IsHighResolution)
            {
                throw new NotSupportedException();
            }

            _cacheName  = name;
            _cacheCount = cacheCount;
            _counters   = IICPerformanceCounterFactory.GetCounters <PerfCounters>(_cacheName);
            _tracing    = TracingManager.GetTracing("LRUCacheManager." + _cacheName);
        }
        internal RpcTransparentService(T serviceObj, string serviceUrl)
            : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            p_serviceName = serviceAttr.ServiceName;
            _serviceObj   = serviceObj;
            _serviceUrl   = serviceUrl;

            IICPerformanceCounterCategory category =
                new IICPerformanceCounterCategory("rpc:" + p_serviceName,
                                                  PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                string methodName = method.Name;


                DynamicMethod dm = new DynamicMethod("fun", typeof(object[]),
                                                     new[] { typeof(RpcServerContext) });

                RpcServiceMethod m = new RpcServiceMethod();
                m.RatePerSecond = category.CreateCounter(methodName + " /sec.",
                                                         PerformanceCounterType.RateOfCountsPerSecond32);
                m.TotalCount = category.CreateCounter(methodName + " Total.",
                                                      PerformanceCounterType.NumberOfItems32);
                m.TotalFailed = category.CreateCounter(methodName + " Failed.",
                                                       PerformanceCounterType.NumberOfItems32);
                m.Concurrent = category.CreateCounter(methodName + " Concurrent.",
                                                      PerformanceCounterType.NumberOfItems32);
                m.Method = method;

                RpcGetArgsHelper.RegisterMethod(p_serviceName, m);

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
Beispiel #7
0
        public LazyQueue(string queueName, int maxBatchCount, int maxIdleMs, Action <T[]> dequeueAction, bool enabledCounters)
        {
            _queueName     = queueName;
            _batchCount    = maxBatchCount;
            _idleMs        = maxIdleMs;
            _dequeueAction = dequeueAction;
            _capacity      = 65536;
            _lastTick      = Environment.TickCount;

            _tracing = TracingManager.GetTracing("LazyQueue." + queueName);
            if (enabledCounters)
            {
                _counters = IICPerformanceCounterFactory.GetCounters <LazyQueuePerfCounters>(queueName);
            }

            _thread              = new Thread(new ThreadStart(ThreadProc));
            _thread.Name         = string.Format("LazyQueue<{0}>:{1}", typeof(T).Name, queueName);
            _thread.IsBackground = true;
            _thread.Start();
        }
Beispiel #8
0
        public ParallelQueue(string queueName, int maxBatchCount, int maxIdleMs, Action <K, V[]> dequeueAction)
        {
            _queueName     = queueName;
            _maxBatchCount = maxBatchCount;
            _maxIdleMs     = maxIdleMs;
            _dequeueAction = dequeueAction;

            _tracing      = TracingManager.GetTracing("ParalelQueue." + queueName);
            _perfCounters = IICPerformanceCounterFactory.GetCounters <ParallelQueuePerfCounters>(queueName);

            _thread = new Thread(ThreadProc);
            _thread.IsBackground = true;
            _thread.Start();

            int max;
            int foo;

            ThreadPool.GetMaxThreads(out max, out foo);
            _defendWorkerThreadCounts = max / 8;
        }