[rabbitmq-discuss] rabbitMQ/Beam only using one core.

Davis, Jeremy jdavis at gridpoint.com
Wed Feb 24 01:57:43 GMT 2010


I have put together a simple producer (in java) that tries to push through as much data as possible.
I create many threads, and each has its own connection, own direct exchange, and own queue.
No matter how many connections, threads, exchanges, or queues, 'top' shows a single beam process at 100%, with remaining 7 cores idle.

I am running 1.7.2 on ubuntu hardy-heron.

Any thoughts?

------------------------------------------------------------------------------
//Simplified java below:

    private static ConnectionFactory    factory     = null;

    public RabbitMqProducer()
    {
        ConnectionParameters params = new ConnectionParameters();
        params.setUsername(userName);
        params.setPassword(password);
        params.setVirtualHost(virtualHost);
        params.setRequestedHeartbeat(0);
        factory = new ConnectionFactory(params);
    }

    public static String getExchangeName( int id )
    {
        return( "rabbitTestExchange-" + id );
    }

    public static String getQueueName( int id )
    {
        return( "rabbitTestQueue-" + id );
    }

    public void go()
        throws Exception
    {
        List<Writer> writers = new ArrayList<Writer>();
        for( int x=0;x<numThreads;x++)
        {
            writers.add(new Writer(x));
        }
        for( int x=0;x<numThreads;x++)
        {
            writers.get(x).start();
        }
    }

    private final class Writer
        extends Thread
    {
        private final int id;
        private Connection  connection  = null;
        private Channel     channel     = null;

        public Writer( int id)
            throws Exception
        {
            this.id = id;
            connect();
        }

        public void connect()
            throws Exception
        {
            connection  = factory.newConnection(hostName, portNumber);
            channel     = connection.createChannel();
            boolean durable = true;
            AMQP.Exchange.DeclareOk eok = channel.exchangeDeclare( getExchangeName(id), "direct", durable );
            AMQP.Queue.DeclareOk qok = channel.queueDeclare(getQueueName(id), durable);
            AMQP.Queue.BindOk    bok = channel.queueBind(getQueueName(id), getExchangeName(id), getQueueName(id) );
        }


        public void send()
            throws Exception
        {
            boolean mandatory = true;  //Returns error if can't send to queue. (and persisted for example).
            boolean immediate = false; //if true, error if can't be consumer immediately.
            StringBuilder b = new StringBuilder( msg.toString() );
            b.append("-"+id);
            byte[] data = b.toString().getBytes();

            for( int x=0;x<numRecords;x++)
            {
                AMQP.BasicProperties props = new AMQP.BasicProperties();
                props.setDeliveryMode(2); //persistent message.
                channel.basicPublish(getExchangeName(id), getQueueName(id), mandatory, immediate, props, data);
            }
        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20100223/9949d840/attachment.htm 


More information about the rabbitmq-discuss mailing list