Example #1
0
    private static void DoBenchmark()
    {
        Timer t = new Timer();

        t.Start();
        rc = new ReferenceCounted();
        for (int i = 0; i < NumIterations; i++)
        {
            rc2 = rc;
            rc3 = rc2;
            rc  = rc3;
            rc3 = rc;
        }
        t.End();
        Console.WriteLine("Reference counted: {0}", t.Interval);

        t.Start();
        gc = new TracingGC();
        for (int i = 0; i < NumIterations; i++)
        {
            gc2 = gc;
            gc3 = gc2;
            gc  = gc3;
            gc3 = gc;
        }
        t.End();
        Console.WriteLine("Tracing GC: {0}", t.Interval);
    }
Example #2
0
 private static void DoBenchmark()
 {
     Timer t = new Timer();
     
     t.Start();
     rc = new ReferenceCounted();
     for( int i = 0; i < NumIterations; i++ )
     {
         rc2 = rc;
         rc3 = rc2;
         rc = rc3;
         rc3 = rc;
         
     }        
     t.End();
     Console.WriteLine( "Reference counted: {0}", t.Interval );
     
     t.Start();
     gc = new TracingGC();
     for( int i = 0; i < NumIterations; i++ )
     {
         gc2 = gc;
         gc3 = gc2;
         gc = gc3;
         gc3 = gc;
     }
     t.End();
     Console.WriteLine( "Tracing GC: {0}", t.Interval ); 
 }
Example #3
0
            // private methods
            private IConnectionHandle AcquireOrCreateConnection()
            {
                PooledConnection connection = _pool._connectionHolder.Acquire();

                if (connection == null)
                {
                    var addingConnectionEventHandler = _pool._addingConnectionEventHandler;
                    if (addingConnectionEventHandler != null)
                    {
                        addingConnectionEventHandler(new ConnectionPoolAddingConnectionEvent(_pool._serverId, EventContext.OperationId));
                    }

                    var stopwatch = Stopwatch.StartNew();
                    connection = _pool.CreateNewConnection();
                    stopwatch.Stop();

                    var addedConnectionEventHandler = _pool._addedConnectionEventHandler;
                    if (addedConnectionEventHandler != null)
                    {
                        addedConnectionEventHandler(new ConnectionPoolAddedConnectionEvent(connection.ConnectionId, stopwatch.Elapsed, EventContext.OperationId));
                    }
                }

                var reference = new ReferenceCounted <PooledConnection>(connection, _pool.ReleaseConnection);

                return(new AcquiredConnection(_pool, reference));
            }
        public void Decrement_should_call_dispose_when_reference_count_is_zero()
        {
            var subject = new ReferenceCounted<IDisposable>(_disposable);

            subject.DecrementReferenceCount();

            subject.ReferenceCount.Should().Be(0);
            _disposable.Received().Dispose();
        }
        public void Decrement_should_call_dispose_when_reference_count_is_zero()
        {
            var subject = new ReferenceCounted<IDisposable>(_mockDisposable.Object);

            subject.DecrementReferenceCount();

            subject.ReferenceCount.Should().Be(0);
            _mockDisposable.Verify(d => d.Dispose(), Times.Once);
        }
        public void Decrement_should_not_call_dispose_when_reference_count_is_greater_than_zero()
        {
            var subject = new ReferenceCounted<IDisposable>(_disposable);

            subject.IncrementReferenceCount();
            subject.DecrementReferenceCount();

            subject.ReferenceCount.Should().Be(1);
            _disposable.DidNotReceive().Dispose();
        }
        public void Decrement_should_not_call_dispose_when_reference_count_is_greater_than_zero()
        {
            var subject = new ReferenceCounted<IDisposable>(_mockDisposable.Object);

            subject.IncrementReferenceCount();
            subject.DecrementReferenceCount();

            subject.ReferenceCount.Should().Be(1);
            _mockDisposable.Verify(d => d.Dispose(), Times.Never);
        }
        public IHttpActionResult ReferenceCount()
        {
            Barrier barrier = new Threading.Barrier(100, (x) =>
            {
                x.SignalAndWait();
            });


            ReferenceCounted <Barrier> counter = new ReferenceCounted <Threading.Barrier>(barrier);

            return(Json(counter));
        }
        public IHttpActionResult ReferenceCount()
        {
            Barrier barrier = new Threading.Barrier(100, (x) =>
            {

                x.SignalAndWait();
            });


            ReferenceCounted<Barrier> counter = new ReferenceCounted<Threading.Barrier>(barrier);
            return Json(counter);


        }
Example #10
0
            private IConnectionHandle EndCheckingOut(PooledConnection pooledConnection, Stopwatch stopwatch)
            {
                var reference        = new ReferenceCounted <PooledConnection>(pooledConnection, _pool.ReleaseConnection);
                var connectionHandle = new AcquiredConnection(_pool, reference);

                stopwatch.Stop();
                var checkedOutConnectionEvent = new ConnectionPoolCheckedOutConnectionEvent(connectionHandle.ConnectionId, stopwatch.Elapsed, EventContext.OperationId);

                _pool._checkedOutConnectionEventHandler?.Invoke(checkedOutConnectionEvent);

                // no need to release the semaphore
                _poolQueueWaitResult = SemaphoreSlimSignalable.SemaphoreWaitResult.None;

                return(connectionHandle);
            }
            private AcquiredConnection FinalizePoolEnterance(PooledConnection pooledConnection)
            {
                if (pooledConnection != null)
                {
                    var reference        = new ReferenceCounted <PooledConnection>(pooledConnection, _pool.ReleaseConnection);
                    var connectionHandle = new AcquiredConnection(_pool, reference);

                    var checkedOutConnectionEvent = new ConnectionPoolCheckedOutConnectionEvent(connectionHandle.ConnectionId, _stopwatch.Elapsed, EventContext.OperationId);
                    _pool._checkedOutConnectionEventHandler?.Invoke(checkedOutConnectionEvent);

                    return(connectionHandle);
                }
                else
                {
                    _stopwatch.Stop();

                    var message = $"Timed out waiting for a connection after {_stopwatch.ElapsedMilliseconds}ms.";
                    throw new TimeoutException(message);
                }
            }
Example #12
0
        private IConnectionHandle AcquireConnection()
        {
            PooledConnection connection = _connectionHolder.Acquire();

            if (connection == null)
            {
                if (_listener != null)
                {
                    _listener.ConnectionPoolBeforeAddingAConnection(new ConnectionPoolBeforeAddingAConnectionEvent(_serverId));
                }
                var stopwatch = Stopwatch.StartNew();
                connection = CreateNewConnection();
                stopwatch.Stop();
                if (_listener != null)
                {
                    _listener.ConnectionPoolAfterAddingAConnection(new ConnectionPoolAfterAddingAConnectionEvent(connection.ConnectionId, stopwatch.Elapsed));
                }
            }

            var reference = new ReferenceCounted <PooledConnection>(connection, x => ReleaseConnection(x));

            return(new AcquiredConnection(this, reference));
        }
Example #13
0
 ReleasingTask(ReferenceCounted obj, int decrement)
 {
     this.obj       = obj;
     this.decrement = decrement;
 }
 private ChannelSourceHandle(ReferenceCounted <IChannelSource> reference)
 {
     _reference = reference;
 }
 private ReadBindingHandle(ReferenceCounted<IReadBinding> reference)
 {
     _reference = reference;
 }
        public void Initial_reference_count_should_be_one()
        {
            var subject = new ReferenceCounted<IDisposable>(_disposable);

            subject.ReferenceCount.Should().Be(1);
        }
Example #17
0
 private ReadBindingHandle(ReferenceCounted <IReadBinding> reference)
 {
     _reference = reference;
 }
            // private methods
            private IConnectionHandle AcquireOrCreateConnection()
            {
                PooledConnection connection = _pool._connectionHolder.Acquire();
                if (connection == null)
                {
                    var addingConnectionEventHandler = _pool._addingConnectionEventHandler;
                    if (addingConnectionEventHandler != null)
                    {
                        addingConnectionEventHandler(new ConnectionPoolAddingConnectionEvent(_pool._serverId, EventContext.OperationId));
                    }

                    var stopwatch = Stopwatch.StartNew();
                    connection = _pool.CreateNewConnection();
                    stopwatch.Stop();

                    var addedConnectionEventHandler = _pool._addedConnectionEventHandler;
                    if (addedConnectionEventHandler != null)
                    {
                        addedConnectionEventHandler(new ConnectionPoolAddedConnectionEvent(connection.ConnectionId, stopwatch.Elapsed, EventContext.OperationId));
                    }
                }

                var reference = new ReferenceCounted<PooledConnection>(connection, _pool.ReleaseConnection);
                return new AcquiredConnection(_pool, reference);
            }
 private ConnectionSourceHandle(ReferenceCounted<IConnectionSource> reference)
 {
     _reference = reference;
 }
 private ChannelSourceHandle(ReferenceCounted<IChannelSource> reference)
 {
     _reference = reference;
 }
Example #21
0
 public AcquiredConnection(ExclusiveConnectionPool connectionPool, ReferenceCounted <PooledConnection> reference)
 {
     _connectionPool = connectionPool;
     _reference      = reference;
 }
        private IConnectionHandle AcquireConnection()
        {
            PooledConnection connection = _connectionHolder.Acquire();
            if (connection == null)
            {
                if (_addingConnectionEventHandler != null)
                {
                    _addingConnectionEventHandler(new ConnectionPoolAddingConnectionEvent(_serverId));
                }
                var stopwatch = Stopwatch.StartNew();
                connection = CreateNewConnection();
                stopwatch.Stop();

                if (_addedConnectionEventHandler != null)
                {
                    _addedConnectionEventHandler(new ConnectionPoolAddedConnectionEvent(connection.ConnectionId, stopwatch.Elapsed));
                }
            }

            var reference = new ReferenceCounted<PooledConnection>(connection, ReleaseConnection);
            return new AcquiredConnection(this, reference);
        }
Example #23
0
 private ConnectionSourceHandle(ReferenceCounted <IConnectionSource> reference)
 {
     _reference = reference;
 }
 public AcquiredConnection(ExclusiveConnectionPool connectionPool, ReferenceCounted<PooledConnection> reference)
 {
     _connectionPool = connectionPool;
     _reference = reference;
 }