Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B0DFD17EEF for ; Thu, 17 Sep 2015 22:22:05 +0000 (UTC) Received: (qmail 15245 invoked by uid 500); 17 Sep 2015 22:22:05 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 15218 invoked by uid 500); 17 Sep 2015 22:22:05 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 15209 invoked by uid 99); 17 Sep 2015 22:22:05 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Sep 2015 22:22:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 1BF46181073 for ; Thu, 17 Sep 2015 22:22:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.3 X-Spam-Level: **** X-Spam-Status: No, score=4.3 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RDNS_NONE=2.5] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id IR_IauFJTGrK for ; Thu, 17 Sep 2015 22:21:50 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (unknown [209.188.14.139]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id 6F55742F31 for ; Thu, 17 Sep 2015 22:21:50 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id DE947E00A9 for ; Thu, 17 Sep 2015 22:21:49 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id D85363A1F91 for ; Thu, 17 Sep 2015 22:21:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1703721 - in /qpid/java/trunk/tools: bin/memory-test src/main/java/org/apache/qpid/tools/MemoryConsumptionTestClient.java src/main/resources/logback.xml Date: Thu, 17 Sep 2015 22:21:49 -0000 To: commits@qpid.apache.org From: orudyy@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150917222149.D85363A1F91@svn01-us-west.apache.org> Author: orudyy Date: Thu Sep 17 22:21:49 2015 New Revision: 1703721 URL: http://svn.apache.org/viewvc?rev=1703721&view=rev Log: QPID-6742: Add utility to measure memory consumption on publishing work done by Lorenz Quack and Alex Rudyy Added: qpid/java/trunk/tools/bin/memory-test (with props) qpid/java/trunk/tools/src/main/java/org/apache/qpid/tools/MemoryConsumptionTestClient.java qpid/java/trunk/tools/src/main/resources/logback.xml Added: qpid/java/trunk/tools/bin/memory-test URL: http://svn.apache.org/viewvc/qpid/java/trunk/tools/bin/memory-test?rev=1703721&view=auto ============================================================================== --- qpid/java/trunk/tools/bin/memory-test (added) +++ qpid/java/trunk/tools/bin/memory-test Thu Sep 17 22:21:49 2015 @@ -0,0 +1,175 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# This script is used to measure memory consumption by Qpid Java Broker running in Oracle JDK + +function waitfor() +{ + counter=1 + until grep -a -l "$2" $1 >/dev/null 2>&1 ; do + sleep 1 ; + let "counter += 1" + if [ "$counter" -gt "$3" ]; then + break + fi + done +} + +function awaitBroker() +{ + echo "Awaiting broker..." + waitfor ${QPID_WORK}/log/qpid.log "BRK-1004" "30" + echo "Broker is ready" +} + +function startBroker() +{ + echo "Starting broker" + ${QPID_HOME}/bin/qpid-server -prop qpid.rmi_port=$RMI_PORT 2>${QPID_WORK}/log/qpid.stderr > ${QPID_WORK}/log/qpid.stdout & + brokerpid=$! + echo "Broker started: PID $brokerpid" +} + +function stopBroker() +{ + messageSize=$1 + messageCount=$2 + resultFile=$3 + + echo "Killing broker with pid $brokerpid" + kill -15 $brokerpid 2>&1 1> /dev/null + slip 1 + kill -9 $brokerpid 2>&1 1> /dev/null + grep BRK-1014 ${QPID_WORK}/log/qpid.log | sed 's/,/ /g' | sed 's/^/# /' >> $resultFile + mv ${QPID_WORK}/log/qpid.log ${QPID_WORK}/log/qpid.log.$messageSize_$messageCount + rm -fr $QPID_WORK/default/messages +} + +function performTest() +{ + messageSize=$1 + messageCount=$2 + resultFile=$3 + connections=${4:-1} + sessions=${5:-1} + producers=${6:-1} + + startBroker + awaitBroker + echo "Running test: messageSize=$messageSize messageNumber=$messageCount connections=${connections} sessions=${sessions}" + java -cp "${TOOLS_DIR}/target/qpid-tools-6.0.0-SNAPSHOT.jar:${TOOLS_DIR}/target/dependency/*" -Dqpid.amqp.version=${PROTOCOL} org.apache.qpid.tools.MemoryConsumptionTestClient \ + connections=${connections} sessions=${sessions} producers=${producers} \ + messagecount=${messageCount} size=${messageSize} jmxuser=admin jmxpassword=admin jmxhost=${BROKER_HOSTNAME} jmxport=${RMI_PORT} >> $resultFile + stopBroker $messageSize $messageCount $resultFile +} + +function performMessageNumberTests() +{ + messageSize=$1 + messageNumbers=$2 + resultFile=$3 + + for messageNumber in $messageNumbers + do + performTest $messageSize $messageNumber $resultFile 1 1 1 + done +} + +function performConnectionsTests() +{ + sessionNumber=${1} + connectionsNumbers=$2 + resultFile=$3 + + for connectionsNumber in $connectionsNumbers + do + performTest 0 2 $resultFile ${connectionsNumber} ${sessionNumber} 1 + done +} + +if [ -z ${QPID_HOME+x} ] +then + echo "QPID_HOME environment variable is unset" + exit 1 +else + echo "QPID_HOME=$QPID_HOME" +fi +if [ -z ${QPID_WORK+x} ] +then + echo "QPID_WORK environment variable is unset" + exit 1 +else + echo "QPID_WORK=$QPID_WORK" +fi + +echo "QPID_OPTS=$QPID_OPTS" + +if [ command -v readlink >/dev/null 2>&1 ] +then + TOOLS_DIR=$(dirname $(dirname $(readlink -f ${0}))) +else + TOOLS_DIR=$(dirname $(cd "$(dirname "${0}")"; pwd)) +fi +echo "Tools module folder ${TOOLS_DIR}" + +if [ ! -d ${TOOLS_DIR}/target ] +then + echo "target directory does not exists run: mvn package" + exit 1 +fi + +if [ ! -d ${TOOLS_DIR}/target/dependency ] +then + echo "target dependencies directory does not exists run: mvn dependency:copy-dependencies" + exit 1 +fi + +PROTOCOL=${1:-0-9} +BROKER_HOSTNAME=${2:-"localhost"} +RMI_PORT=${3:-8999} + +javaVersion=`java -version 2>&1 | grep "java version" | awk '{print $3}' | sed -e "s/\"//g"` +startTime=`date "+%Y-%m-%d %H:%M:%S"` +startTimeFile=`date "+%Y-%m-%d-%H-%M-%S"` +resultFile="${TOOLS_DIR}/target/results-${PROTOCOL}-${javaVersion}-${startTimeFile}.txt" + +echo "Results will be written into ${resultFile}" + +rm -fr $QPID_WORK +mkdir -p ${QPID_WORK}/log + +echo "# $startTime" > ${resultFile} +echo "# amqp=${PROTOCOL} java=${javaVersion} QPID_OPTS=${QPID_OPTS}" >> ${resultFile} +echo "heap usage, direct memory usage, connections, sessions, producers, is transacted, messages, message size, delivery mode, user friendly heap usage, user friendly direct memory usage" >> ${resultFile} + +performMessageNumberTests 0 "10 50 100 1000 10000 100000 1000000" ${resultFile} +performMessageNumberTests 1024 "10 50 100 1000 10000 100000 1000000" ${resultFile} +performMessageNumberTests 102400 "10 50 100 1000 10000 100000" ${resultFile} +performMessageNumberTests 1048576 "10 50 100 1000 10000" ${resultFile} +performMessageNumberTests 10485760 "10 50 100 1000" ${resultFile} +performMessageNumberTests 32768000 "10 50 100" ${resultFile} + +performConnectionsTests 1 "1 100 1000 10000" ${resultFile} +performConnectionsTests 10 "1 100 1000 10000" ${resultFile} +performConnectionsTests 100 "1 100 1000 10000" ${resultFile} +performConnectionsTests 200 "1 100 1000 10000" ${resultFile} + +endTime=`date "+%Y-%m-%d %H:%M:%S"` +echo "# $endTime" >> results.txt Propchange: qpid/java/trunk/tools/bin/memory-test ------------------------------------------------------------------------------ svn:executable = * Added: qpid/java/trunk/tools/src/main/java/org/apache/qpid/tools/MemoryConsumptionTestClient.java URL: http://svn.apache.org/viewvc/qpid/java/trunk/tools/src/main/java/org/apache/qpid/tools/MemoryConsumptionTestClient.java?rev=1703721&view=auto ============================================================================== --- qpid/java/trunk/tools/src/main/java/org/apache/qpid/tools/MemoryConsumptionTestClient.java (added) +++ qpid/java/trunk/tools/src/main/java/org/apache/qpid/tools/MemoryConsumptionTestClient.java Thu Sep 17 22:21:49 2015 @@ -0,0 +1,453 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.tools; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import javax.jms.BytesMessage; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; +import javax.jms.Destination; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.management.MBeanServerConnection; +import javax.management.Notification; +import javax.management.NotificationListener; +import javax.management.ObjectName; +import javax.management.openmbean.CompositeData; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import com.sun.management.GarbageCollectionNotificationInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.qpid.QpidException; +import org.apache.qpid.client.AMQDestination; +import org.apache.qpid.client.AMQSession; + + +public class MemoryConsumptionTestClient +{ + private static final Logger LOGGER = LoggerFactory.getLogger(MemoryConsumptionTestClient.class); + + private static final String QUEUE_NAME_PREFIX = "BURL:direct://amq.direct//memory-test-queue"; + private static final String DURABLE_SUFFIX = "?durable='true'"; + + public static final String CONNECTIONS_ARG = "connections"; + public static final String SESSIONS_ARG = "sessions"; + public static final String PRODUCERS_ARG = "producers"; + public static final String MESSAGE_COUNT_ARG = "messagecount"; + public static final String MESSAGE_SIZE_ARG = "size"; + public static final String PERSISTENT_ARG = "persistent"; + public static final String TIMEOUT_ARG = "timeout"; + public static final String TRANSACTED_ARG = "transacted"; + public static final String JMX_HOST_ARG = "jmxhost"; + public static final String JMX_PORT_ARG = "jmxport"; + public static final String JMX_USER_ARG = "jmxuser"; + public static final String JMX_USER_PASSWORD_ARG = "jmxpassword"; + + public static final String CONNECTIONS_DEFAULT = "1"; + public static final String SESSIONS_DEFAULT = "1"; + public static final String PRODUCERS_DEFAULT = "1"; + public static final String MESSAGE_COUNT_DEFAULT = "1"; + public static final String MESSAGE_SIZE_DEFAULT = "256"; + public static final String PERSISTENT_DEFAULT = "false"; + public static final String TIMEOUT_DEFAULT = "1000"; + public static final String TRANSACTED_DEFAULT = "false"; + + private static final String JMX_HOST_DEFAULT = "localhost"; + private static final String JMX_PORT_DEFAULT = "8999"; + private static final String JMX_GARBAGE_COLLECTOR_MBEAN = "gc"; + + public static void main(String[] args) + { + Map options = new HashMap<>(); + options.put(CONNECTIONS_ARG, CONNECTIONS_DEFAULT); + options.put(SESSIONS_ARG, SESSIONS_DEFAULT); + options.put(PRODUCERS_ARG, PRODUCERS_DEFAULT); + options.put(MESSAGE_COUNT_ARG, MESSAGE_COUNT_DEFAULT); + options.put(MESSAGE_SIZE_ARG, MESSAGE_SIZE_DEFAULT); + options.put(PERSISTENT_ARG, PERSISTENT_DEFAULT); + options.put(TIMEOUT_ARG, TIMEOUT_DEFAULT); + options.put(TRANSACTED_ARG, TRANSACTED_DEFAULT); + options.put(JMX_HOST_ARG, JMX_HOST_DEFAULT); + options.put(JMX_PORT_ARG, JMX_PORT_DEFAULT); + options.put(JMX_USER_ARG, ""); + options.put(JMX_USER_PASSWORD_ARG, ""); + options.put(JMX_GARBAGE_COLLECTOR_MBEAN, "java.lang:type=GarbageCollector,name=ConcurrentMarkSweep"); + + if(args.length == 1 && + (args[0].equals("-h") || args[0].equals("--help") || args[0].equals("help"))) + { + System.out.println("arg=value options: \n" + options.keySet()); + return; + } + + parseArgumentsIntoConfig(options, args); + + MemoryConsumptionTestClient testClient = new MemoryConsumptionTestClient(); + testClient.runTest(options); + } + + public static void parseArgumentsIntoConfig(Map initialValues, String[] args) + { + for(String arg: args) + { + int equalPos = arg.indexOf('='); + if(equalPos == -1) + { + throw new IllegalArgumentException("arguments must have format =: " + arg); + } + + if(initialValues.put(arg.substring(0, equalPos), arg.substring(equalPos + 1)) == null) + { + throw new IllegalArgumentException("not a valid configuration property: " + arg); + } + } + } + + + private void runTest(Map options) + { + int numConnections = Integer.parseInt(options.get(CONNECTIONS_ARG)); + int numSessions = Integer.parseInt(options.get(SESSIONS_ARG)); + int numProducers = Integer.parseInt(options.get(PRODUCERS_ARG)); + int numMessage = Integer.parseInt(options.get(MESSAGE_COUNT_ARG)); + int messageSize = Integer.parseInt(options.get(MESSAGE_SIZE_ARG)); + String queueString = QUEUE_NAME_PREFIX + DURABLE_SUFFIX; + int deliveryMode = Boolean.valueOf(options.get(PERSISTENT_ARG)) ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; + long receiveTimeout = Long.parseLong(options.get(TIMEOUT_ARG)); + boolean transacted = Boolean.valueOf(options.get(TRANSACTED_ARG)); + + LOGGER.info("Using options: " + options); + + try + { + // Load JNDI properties + Properties properties = new Properties(); + try(InputStream is = this.getClass().getClassLoader().getResourceAsStream("stress-test-client.properties")) + { + properties.load(is); + } + + ConnectionFactory conFac = createConnectionFactory(properties); + Destination destination = ensureQueueCreated(queueString, conFac); + Map> connectionsAndSessions = openConnectionsAndSessions(numConnections, numSessions, transacted, conFac); + publish(numMessage, messageSize, numProducers, deliveryMode, destination, connectionsAndSessions); + MemoryStatistic memoryStatistics = collectMemoryStatistics(options); + generateCSV(memoryStatistics, numConnections, numSessions, transacted, numMessage, messageSize, numProducers, deliveryMode); + purgeQueue(conFac, queueString, receiveTimeout); + closeConnections(connectionsAndSessions.keySet()); + } + catch (Exception e) + { + LOGGER.error("Exception on running the test", e); + } + } + + private void generateCSV(MemoryStatistic memoryStatistics, int numConnections, int numSessions, boolean transacted, int numMessage, int messageSize, int numProducers, int deliveryMode) + { + System.out.println(memoryStatistics.getHeapUsage() + "," + memoryStatistics.getDirectMemoryUsage() + + "," + numConnections + "," + numSessions + "," + numProducers + "," + transacted + "," + numMessage + + "," + messageSize + "," + deliveryMode + "," + toUserFriendlyName(memoryStatistics.getHeapUsage()) + + "," + toUserFriendlyName(memoryStatistics.getDirectMemoryUsage())); + } + + private void publish(int numberOfMessages, int messageSize, int numberOfProducers, int deliveryMode, + Destination destination, Map> connectionsAndSessions) throws JMSException + { + byte[] messageBytes = generateMessage(messageSize); + for (List sessions : connectionsAndSessions.values()) + { + for (Session session: sessions) + { + BytesMessage message = session.createBytesMessage(); + + if (messageSize > 0) + { + message.writeBytes(messageBytes); + } + + for(int i = 0; i < numberOfProducers ; i++) + { + MessageProducer prod = session.createProducer(destination); + for(int j = 0; j < numberOfMessages ; j++) + { + prod.send(message, deliveryMode, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); + if(session.getTransacted()) + { + session.commit(); + } + } + } + } + } + } + + private Map> openConnectionsAndSessions(int numConnections, int numSessions, boolean transacted, ConnectionFactory conFac) throws JMSException + { + Map> connectionAndSessions = new HashMap<>(); + for (int i= 0; i < numConnections ; i++) + { + Connection connection = conFac.createConnection(); + connection.setExceptionListener(new ExceptionListener() + { + public void onException(JMSException jmse) + { + LOGGER.error("The sample received an exception through the ExceptionListener", jmse); + System.exit(1); + } + }); + + List sessions = new ArrayList<>(); + connectionAndSessions.put(connection, sessions); + connection.start(); + for (int s= 0; s < numSessions ; s++) + { + Session session = connection.createSession(transacted, transacted?Session.SESSION_TRANSACTED:Session.AUTO_ACKNOWLEDGE); + sessions.add(session); + } + } + return connectionAndSessions; + } + + private Destination ensureQueueCreated(String queueURL, ConnectionFactory connectionFactory) throws JMSException + { + Connection connection = connectionFactory.createConnection(); + Destination destination = null; + try + { + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + destination = session.createQueue(queueURL); + MessageConsumer consumer = session.createConsumer(destination); + consumer.close(); + session.close(); + } + finally + { + connection.close(); + } + return destination; + } + + private ConnectionFactory createConnectionFactory(Properties properties) throws NamingException + { + ConnectionFactory connectionFactory = null; + Context ctx = new InitialContext(properties); + try + { + connectionFactory = (ConnectionFactory) ctx.lookup("qpidConnectionfactory"); + } + finally + { + ctx.close(); + } + return connectionFactory; + } + + private void closeConnections(Collection connections) throws JMSException, NamingException + { + for (Connection c: connections) + { + c.close(); + } + } + + private void purgeQueue(ConnectionFactory connectionFactory, String queueString, long receiveTimeout) throws JMSException, QpidException + { + LOGGER.debug("Consuming left over messages, using receive timeout:" + receiveTimeout); + + Connection connection = connectionFactory.createConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Destination destination = session.createQueue(queueString); + MessageConsumer consumer = session.createConsumer(destination); + connection.start(); + + int count = 0; + while(true) + { + BytesMessage msg = (BytesMessage) consumer.receive(receiveTimeout); + + if(msg == null) + { + long queueDepth = ((AMQSession)session).getQueueDepth((AMQDestination)destination); + if (queueDepth == 0) + { + LOGGER.debug("Received " + count + " messages"); + break; + } + } + else + { + count++; + } + } + + consumer.close(); + session.close(); + connection.close(); + } + + private MemoryStatistic collectMemoryStatistics(Map options) throws Exception + { + String host = options.get(JMX_HOST_ARG); + String port = options.get(JMX_PORT_ARG); + String user = options.get(JMX_USER_ARG); + String password = options.get(JMX_USER_PASSWORD_ARG); + + if (!"".equals(host) && !"".equals(port) && !"".equals(user) && !"".equals(password)) + { + final MemoryStatistic memoryStatistics = new MemoryStatistic(); + Map environment = Collections.singletonMap(JMXConnector.CREDENTIALS, new String[]{user, password}); + JMXConnector jmxConnector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL("rmi", "", 0, "/jndi/rmi://" + host + ":" + port + "/jmxrmi"), environment); + jmxConnector.connect(); + try + { + final MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection(); + final ObjectName memoryMBean = new ObjectName("java.lang:type=Memory"); + ObjectName gcMBean = new ObjectName(options.get(JMX_GARBAGE_COLLECTOR_MBEAN)); + final CountDownLatch notificationReceived = new CountDownLatch(1); + mBeanServerConnection.addNotificationListener(gcMBean, new NotificationListener() + { + @Override + public void handleNotification(Notification notification, Object handback) + { + if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) + { + GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()); + String gcCause = info.getGcCause(); + if (gcCause.equals("System.gc()") && info.getGcAction().contains("end of major GC")) + { + try + { + Object heapMemoryUsage = mBeanServerConnection.getAttribute(memoryMBean, "HeapMemoryUsage"); + Object used = ((CompositeData) heapMemoryUsage).get("used"); + Object directMemoryTotalCapacity = mBeanServerConnection.getAttribute(new ObjectName("java.nio:type=BufferPool,name=direct"), "TotalCapacity"); + + memoryStatistics.setHeapUsage(Long.parseLong(String.valueOf(used))); + memoryStatistics.setDirectMemoryUsage(Long.parseLong(String.valueOf(directMemoryTotalCapacity))); + } + catch (Exception e) + { + e.printStackTrace(); + } + finally + { + notificationReceived.countDown(); + } + } + } + } + }, null, null ); + + mBeanServerConnection.invoke(memoryMBean, "gc", null, null); + notificationReceived.await(5, TimeUnit.SECONDS); + + } + finally + { + jmxConnector.close(); + } + + return memoryStatistics; + } + else + { + return null; + } + } + + private String toUserFriendlyName(Object intValue) + { + long value = Long.parseLong(String.valueOf(intValue)); + if (value <= 1024) + { + return String.valueOf(value) + "B"; + } + else if (value <= 1024 * 1024) + { + return String.valueOf(value/1024) + "kB"; + } + else if (value <= 1024l * 1024l * 1024l) + { + return String.valueOf(value/1024l/1024l) + "MB"; + } + else + { + return String.valueOf(value/1024l/1024l/1024l) + "GB"; + } + } + + + private byte[] generateMessage(int messageSize) + { + byte[] sentBytes = new byte[messageSize]; + for(int r = 0 ; r < messageSize ; r++) + { + sentBytes[r] = (byte) (48 + (r % 10)); + } + return sentBytes; + } + + private class MemoryStatistic + { + private long heapUsage; + private long directMemoryUsage; + + public long getHeapUsage() + { + return heapUsage; + } + + public void setHeapUsage(long heapUsage) + { + this.heapUsage = heapUsage; + } + + public long getDirectMemoryUsage() + { + return directMemoryUsage; + } + + public void setDirectMemoryUsage(long directMemoryUsage) + { + this.directMemoryUsage = directMemoryUsage; + } + } +} Added: qpid/java/trunk/tools/src/main/resources/logback.xml URL: http://svn.apache.org/viewvc/qpid/java/trunk/tools/src/main/resources/logback.xml?rev=1703721&view=auto ============================================================================== --- qpid/java/trunk/tools/src/main/resources/logback.xml (added) +++ qpid/java/trunk/tools/src/main/resources/logback.xml Thu Sep 17 22:21:49 2015 @@ -0,0 +1,38 @@ + + + + + + tools.log + true + + %date %-7X{origin} %-5level [%thread] %logger{10} %msg%n + + + + + + + + + + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org