Search in sources :

Example 16 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class Connection method takeFromOutgoingQueue.

private ByteBuffer takeFromOutgoingQueue() throws InterruptedException {
    ByteBuffer result = null;
    final DMStats stats = this.owner.getConduit().stats;
    long start = DistributionStats.getStatTime();
    try {
        synchronized (this.outgoingQueue) {
            if (this.disconnectRequested) {
                // don't bother with anymore work since we are done
                this.asyncQueuingInProgress = false;
                this.outgoingQueue.notifyAll();
                return null;
            }
            // Object o = this.outgoingQueue.poll();
            do {
                if (this.outgoingQueue.isEmpty()) {
                    break;
                }
                Object o = this.outgoingQueue.removeFirst();
                if (o == null) {
                    break;
                }
                if (o instanceof ConflationKey) {
                    result = ((ConflationKey) o).getBuffer();
                    if (result != null) {
                        this.conflatedKeys.remove(o);
                    } else {
                        // queue so we just need to skip this entry
                        continue;
                    }
                } else {
                    result = (ByteBuffer) o;
                }
                int newBytes = result.remaining();
                this.queuedBytes -= newBytes;
                stats.incAsyncQueueSize(-newBytes);
                stats.incAsyncDequeuedMsgs();
            } while (result == null);
            if (result == null) {
                this.asyncQueuingInProgress = false;
                this.outgoingQueue.notifyAll();
            }
        }
        return result;
    } finally {
        if (DistributionStats.enableClockStats) {
            stats.incAsyncQueueRemoveTime(DistributionStats.getStatTime() - start);
        }
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) ConflationKey(org.apache.geode.distributed.internal.ConflationKey) ByteBuffer(java.nio.ByteBuffer)

Example 17 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class Connection method compactOrResizeBuffer.

private void compactOrResizeBuffer(int messageLength) {
    final int oldBufferSize = nioInputBuffer.capacity();
    final DMStats stats = this.owner.getConduit().stats;
    int allocSize = messageLength + MSG_HEADER_BYTES;
    if (oldBufferSize < allocSize) {
        // need a bigger buffer
        logger.info(LocalizedMessage.create(LocalizedStrings.Connection_ALLOCATING_LARGER_NETWORK_READ_BUFFER_NEW_SIZE_IS_0_OLD_SIZE_WAS_1, new Object[] { Integer.valueOf(allocSize), Integer.valueOf(oldBufferSize) }));
        ByteBuffer oldBuffer = nioInputBuffer;
        nioInputBuffer = Buffers.acquireReceiveBuffer(allocSize, stats);
        if (oldBuffer != null) {
            int oldByteCount = oldBuffer.remaining();
            nioInputBuffer.put(oldBuffer);
            nioInputBuffer.position(oldByteCount);
            Buffers.releaseReceiveBuffer(oldBuffer, stats);
        }
    } else {
        if (nioInputBuffer.position() != 0) {
            nioInputBuffer.compact();
        } else {
            nioInputBuffer.position(nioInputBuffer.limit());
            nioInputBuffer.limit(nioInputBuffer.capacity());
        }
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) ByteBuffer(java.nio.ByteBuffer)

Example 18 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class Connection method runNioPusher.

/**
   * have the pusher thread check for queue overflow and for idle time exceeded
   */
protected void runNioPusher() {
    try {
        final DMStats stats = this.owner.getConduit().stats;
        final long threadStart = stats.startAsyncThread();
        try {
            stats.incAsyncQueues(1);
            stats.incAsyncThreads(1);
            try {
                int flushId = 0;
                while (this.asyncQueuingInProgress && this.connected) {
                    if (SystemFailure.getFailure() != null) {
                        // Allocate no objects here!
                        Socket s = this.socket;
                        if (s != null) {
                            try {
                                s.close();
                            } catch (IOException e) {
                            // don't care
                            }
                        }
                        // throws
                        SystemFailure.checkFailure();
                    }
                    if (this.owner.getConduit().getCancelCriterion().isCancelInProgress()) {
                        break;
                    }
                    flushId++;
                    long flushStart = stats.startAsyncQueueFlush();
                    try {
                        long curQueuedBytes = this.queuedBytes;
                        if (curQueuedBytes > this.asyncMaxQueueSize) {
                            logger.warn(LocalizedMessage.create(LocalizedStrings.Connection_QUEUED_BYTES_0_EXCEEDS_MAX_OF_1_ASKING_SLOW_RECEIVER_2_TO_DISCONNECT, new Object[] { curQueuedBytes, this.asyncMaxQueueSize, this.remoteAddr }));
                            stats.incAsyncQueueSizeExceeded(1);
                            disconnectSlowReceiver();
                            return;
                        }
                        SocketChannel channel = getSocket().getChannel();
                        ByteBuffer bb = takeFromOutgoingQueue();
                        if (bb == null) {
                            if (logger.isDebugEnabled() && flushId == 1) {
                                logger.debug("P2P pusher found empty queue");
                            }
                            return;
                        }
                        nioWriteFully(channel, bb, true, null);
                        // We should not add messagesSent here according to Bruce.
                        // The counts are increased elsewhere.
                        // messagesSent++;
                        accessed();
                    } finally {
                        stats.endAsyncQueueFlush(flushStart);
                    }
                }
            // while
            } finally {
                // need to force this to false before doing the requestClose calls
                synchronized (this.outgoingQueue) {
                    this.asyncQueuingInProgress = false;
                    this.outgoingQueue.notifyAll();
                }
            }
        } catch (InterruptedException ex) {
        // someone wants us to stop.
        // No need to set interrupt bit, we're quitting.
        // No need to throw an error, we're quitting.
        } catch (IOException ex) {
            final String err = LocalizedStrings.Connection_P2P_PUSHER_IO_EXCEPTION_FOR_0.toLocalizedString(this);
            if (!isSocketClosed()) {
                if (logger.isDebugEnabled() && !isIgnorableIOException(ex)) {
                    logger.debug(err, ex);
                }
            }
            try {
                requestClose(err + ": " + ex);
            } catch (Exception ignore) {
            }
        } catch (CancelException ex) {
            // bug 37367
            final String err = LocalizedStrings.Connection_P2P_PUSHER_0_CAUGHT_CACHECLOSEDEXCEPTION_1.toLocalizedString(new Object[] { this, ex });
            logger.debug(err);
            try {
                requestClose(err);
            } catch (Exception ignore) {
            }
            return;
        } catch (Exception ex) {
            // bug 37101
            this.owner.getConduit().getCancelCriterion().checkCancelInProgress(ex);
            if (!isSocketClosed()) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_P2P_PUSHER_EXCEPTION_0, ex), ex);
            }
            try {
                requestClose(LocalizedStrings.Connection_P2P_PUSHER_EXCEPTION_0.toLocalizedString(ex));
            } catch (Exception ignore) {
            }
        } finally {
            stats.incAsyncQueueSize(-this.queuedBytes);
            this.queuedBytes = 0;
            stats.endAsyncThread(threadStart);
            stats.incAsyncThreads(-1);
            stats.incAsyncQueues(-1);
            if (logger.isDebugEnabled()) {
                logger.debug("runNioPusher terminated id={} from {}/{}", conduitIdStr, remoteAddr, remoteAddr);
            }
        }
    } finally {
        synchronized (this.nioPusherSync) {
            this.pusherThread = null;
            this.nioPusherSync.notify();
        }
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) DMStats(org.apache.geode.distributed.internal.DMStats) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CancelException(org.apache.geode.CancelException) ByteBuffer(java.nio.ByteBuffer) Socket(java.net.Socket) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) CancelledKeyException(java.nio.channels.CancelledKeyException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 19 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class Connection method nioWriteFully.

/**
   * nioWriteFully implements a blocking write on a channel that is in non-blocking mode.
   * 
   * @param forceAsync true if we need to force a blocking async write.
   * @throws ConnectionException if the conduit has stopped
   */
protected void nioWriteFully(SocketChannel channel, ByteBuffer buffer, boolean forceAsync, DistributionMessage msg) throws IOException, ConnectionException {
    final DMStats stats = this.owner.getConduit().stats;
    if (!this.sharedResource) {
        stats.incTOSentMsg();
    }
    if (useSyncWrites(forceAsync)) {
        if (this.asyncQueuingInProgress) {
            if (addToQueue(buffer, msg, false)) {
                return;
            }
        // fall through
        }
        long startLock = stats.startSocketLock();
        synchronized (this.outLock) {
            stats.endSocketLock(startLock);
            if (this.asyncQueuingInProgress) {
                if (addToQueue(buffer, msg, false)) {
                    return;
                }
            // fall through
            }
            do {
                int amtWritten = 0;
                long start = stats.startSocketWrite(true);
                try {
                    // this.writerThread = Thread.currentThread();
                    amtWritten = channel.write(buffer);
                } finally {
                    stats.endSocketWrite(true, start, amtWritten, 0);
                // this.writerThread = null;
                }
            } while (buffer.remaining() > 0);
        }
    // synchronized
    } else {
        writeAsync(channel, buffer, forceAsync, msg, stats);
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats)

Example 20 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class Connection method getNIOBuffer.

/** gets the buffer for receiving message length bytes */
protected ByteBuffer getNIOBuffer() {
    final DMStats stats = this.owner.getConduit().stats;
    if (nioInputBuffer == null) {
        int allocSize = this.recvBufferSize;
        if (allocSize == -1) {
            allocSize = this.owner.getConduit().tcpBufferSize;
        }
        nioInputBuffer = Buffers.acquireReceiveBuffer(allocSize, stats);
    }
    return nioInputBuffer;
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats)

Aggregations

DMStats (org.apache.geode.distributed.internal.DMStats)29 Region (org.apache.geode.cache.Region)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)10 Properties (java.util.Properties)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)9 Test (org.junit.Test)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)7 CacheException (org.apache.geode.cache.CacheException)6 DM (org.apache.geode.distributed.internal.DM)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 Iterator (java.util.Iterator)3 Set (java.util.Set)3 IgnoredException (org.apache.geode.test.dunit.IgnoredException)3 VM (org.apache.geode.test.dunit.VM)3 InterruptedIOException (java.io.InterruptedIOException)2 ConnectException (java.net.ConnectException)2 SocketException (java.net.SocketException)2