Skip to content

Instantly share code, notes, and snippets.

@lyrixx
Last active February 6, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyrixx/48063c011134e58562b648bb4c1e63f8 to your computer and use it in GitHub Desktop.
Save lyrixx/48063c011134e58562b648bb4c1e63f8 to your computer and use it in GitHub Desktop.
RabbitMQ reproducer

RabbitMQ reproducer

Reproducer for rabbitmq/discussions#59

Installation

  1. git clone git@gist.github.com:48063c011134e58562b648bb4c1e63f8.git

  2. docker-compose build

  3. docker-compose up

  4. get the IP of the rabbitmq server:

    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' `docker ps | grep rabbitmq | awk '{print $1}'`
    
  5. Open the admin: http://172.18.0.3:15672/#/ (to be adapted)

  6. Publish many message

    docker-compose run php /app/run.php 10000 # 10000 is the number of message to publish
    
  7. To get the memory_breakdown data:

    docker-compose exec rabbitmq rabbitmq-diagnostics memory_breakdown
    
version: '3.7'
services:
rabbitmq:
image: rabbitmq:3.8.2-management-alpine
environment:
- "RABBITMQ_VM_MEMORY_HIGH_WATERMARK=1024MiB"
php:
build: .
volumes:
- ".:/app:ro"
FROM alpine:3.10
# mirrors in france
RUN echo "http://dl-cdn.alpinelinux.org/alpine/v3.10/main" > /etc/apk/repositories && \
echo "http://dl-cdn.alpinelinux.org/alpine/v3.10/community" >> /etc/apk/repositories
RUN apk upgrade --no-cache --quiet --available
# PHP
RUN apk add --no-cache \
bash \
php7 \
php7-amqp \
php7-ctype \
php7-opcache \
php7-pcntl \
php7-posix \
php7-sockets \
pcre
#!/usr/bin/env php
<?php
$config = [
'host' => 'rabbitmq',
];
$conn = new \AMQPConnection($config);
$conn->connect();
$channel = new \AMQPChannel($conn);
$exchange = new \AMQPExchange($channel);
$exchange->setType(\AMQP_EX_TYPE_DIRECT);
$exchange->setName('test');
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName('test');
$queue->setFlags(\AMQP_DURABLE);
$queue->setArgument('x-queue-mode', 'lazy');
$queue->declareQueue();
$queue->bind('test', 'test');
$payload = str_repeat('x', 1 * 1000 * 1000);
$count = $argv[1] ?? 1;
for ($i=1; $i <= $count; $i++) {
$s = microtime(true);
$exchange->publish($payload, 'test', \AMQP_NOPARAM, ['delivery_mode' => 2]);
if (microtime(true) - $s > 1) {
echo "X";
} else {
echo '.';
}
if (0 === $i % 1000) {
echo "\n";
}
}
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment