コード例 #1
0
ファイル: General.cs プロジェクト: pali88/ravendb
        public bool MaybePulseTransaction()
        {
            if (Interlocked.Increment(ref maybePulseCount) % 1000 != 0)
            {
                return(false);
            }

            lock (maybePulseLock)
            {
                var       sizeInBytes = transactionalStorage.GetDatabaseTransactionVersionSizeInBytes();
                const int maxNumberOfCallsBeforePulsingIsForced = 50 * 1000;
                if (sizeInBytes <= 0) // there has been an error
                {
                    if (maybePulseCount % maxNumberOfCallsBeforePulsingIsForced == 0)
                    {
                        logger.Debug("MaybePulseTransaction() --> PulseTransaction()");
                        PulseTransaction();
                    }
                    return(true);
                }
                var eightyPrecentOfMax = (transactionalStorage.MaxVerPagesValueInBytes * 0.8);
                if (eightyPrecentOfMax <= sizeInBytes || maybePulseCount % maxNumberOfCallsBeforePulsingIsForced == 0)
                {
                    logger.Debug("MaybePulseTransaction() --> PulseTransaction()");
                    PulseTransaction();
                }
                return(true);
            }
        }
コード例 #2
0
        public void MaybePulseTransaction()
        {
            if (++maybePulseCount % 1000 != 0)
            {
                return;
            }

            var       sizeInBytes = transactionalStorage.GetDatabaseTransactionVersionSizeInBytes();
            const int maxNumberOfCallsBeforePulsingIsForced = 50 * 1000;

            if (sizeInBytes <= 0)             // there has been an error
            {
                if (maybePulseCount % maxNumberOfCallsBeforePulsingIsForced == 0)
                {
                    PulseTransaction();
                }
                return;
            }
            var eightyPrecentOfMax = (transactionalStorage.MaxVerPagesValueInBytes * 0.8);

            if (eightyPrecentOfMax <= sizeInBytes || maybePulseCount % maxNumberOfCallsBeforePulsingIsForced == 0)
            {
                PulseTransaction();
            }
        }
コード例 #3
0
        public bool MaybePulseTransaction(int addToPulseCount = 1, Action beforePulseTransaction = null)
        {
            Interlocked.Add(ref totalMaybePulseCount, addToPulseCount);
            var increment = Interlocked.Add(ref maybePulseCount, addToPulseCount);

            if (increment < 1024)
            {
                return(false);
            }

            if (Interlocked.CompareExchange(ref maybePulseCount, 0, increment) != increment)
            {
                return(false);
            }

            lock (maybePulseLock)
            {
                var       sizeInBytes = transactionalStorage.GetDatabaseTransactionVersionSizeInBytes();
                const int maxNumberOfCallsBeforePulsingIsForced = 50 * 1000;
                if (sizeInBytes <= 0) // there has been an error
                {
                    if (totalMaybePulseCount >= maxNumberOfCallsBeforePulsingIsForced)
                    {
                        Interlocked.Exchange(ref totalMaybePulseCount, 0);

                        if (beforePulseTransaction != null)
                        {
                            beforePulseTransaction();
                        }

                        logger.Debug("MaybePulseTransaction() --> PulseTransaction()");
                        PulseTransaction();
                        return(true);
                    }
                    return(false);
                }

                var eightyPrecentOfMax = (transactionalStorage.MaxVerPagesValueInBytes * 0.8);
                if (eightyPrecentOfMax <= sizeInBytes ||
                    totalMaybePulseCount >= maxNumberOfCallsBeforePulsingIsForced)
                {
                    Interlocked.Exchange(ref totalMaybePulseCount, 0);

                    if (beforePulseTransaction != null)
                    {
                        beforePulseTransaction();
                    }

                    logger.Debug("MaybePulseTransaction() --> PulseTransaction()");
                    PulseTransaction();
                    return(true);
                }
                return(false);
            }
        }