public ProducerThread(int threadId, ProducerPerfConfig config, AtomicLong totalBytesSent, AtomicLong totalMessagesSent, CountdownEvent allDone, Random rand)
        {
            this.threadId          = threadId;
            this.config            = config;
            this.totalBytesSent    = totalBytesSent;
            this.totalMessagesSent = totalMessagesSent;
            this.allDone           = allDone;
            this.rand = rand;

            this.producerConfig = new ProducerConfig();

            this.producerConfig.Brokers =
                config.BrokerList.Split(',')
                .Select(
                    (s, idx) =>
                    new BrokerConfiguration
            {
                BrokerId = idx,
                Host     = s.Split(':')[0],
                Port     = int.Parse(s.Split(':')[1])
            }).ToList();

            this.producerConfig.CompressionCodec = config.CompressionCodec;

            this.producerConfig.SendBufferBytes = 64 * 1024;
            if (!config.IsSync)
            {
                this.producerConfig.ProducerType          = ProducerTypes.Async;
                this.producerConfig.BatchNumMessages      = config.BatchSize;
                this.producerConfig.QueueEnqueueTimeoutMs = -1;
            }

            this.producerConfig.ClientId              = "ProducerPerformance";
            this.producerConfig.RequestRequiredAcks   = config.ProducerRequestRequiredAcks;
            this.producerConfig.RequestTimeoutMs      = config.ProducerRequestTimeoutMs;
            this.producerConfig.MessageSendMaxRetries = config.ProducerNumRetries;
            this.producerConfig.RetryBackoffMs        = config.ProducerRetryBackoffMs;

            this.producerConfig.Serializer    = typeof(DefaultEncoder).AssemblyQualifiedName;
            this.producerConfig.KeySerializer = typeof(NullEncoder <long>).AssemblyQualifiedName;

            this.producer = new Producer <long, byte[]>(this.producerConfig);

            this.messagesPerThread = config.NumMessages / config.NumThreads;
            Logger.DebugFormat("Messages per thread = {0}", this.messagesPerThread);
        }
        public static void Main(string[] args)
        {
            var config = new ProducerPerfConfig(args);

            if (!config.IsFixedSize)
            {
                Logger.Warn("Throughput will be slower due to changing message size per request");
            }

            var totalBytesSent    = new AtomicLong(0);
            var totalMessagesSent = new AtomicLong(0);

            var allDone = new CountdownEvent(config.NumThreads);

            var start = DateTime.Now;
            var rand  = new Random();

            if (!config.HideHeader)
            {
                Console.WriteLine("start.time, end.time, compression, message.size, batch.size, total.data.sent.in.MB, MB.sec, " +
                                  "total.data.sent.in.nMsg, nMsg.sec");
            }

            for (var i = 0; i < config.NumThreads; i++)
            {
                new Thread(() => new ProducerThread(i, config, totalBytesSent, totalMessagesSent, allDone, rand).Run()).Start();
            }

            allDone.Wait();
            var end         = DateTime.Now;
            var elapsedSecs = (end - start).TotalSeconds;
            var totalMBSent = (totalBytesSent.Get() * 1.0) / (1024 * 1024);

            Console.WriteLine(
                "{0}; {1}; {2}; {3}; {4}; {5:f2}; {6:f4}; {7}; {8:f4}",
                start.ToString(config.DateFormat),
                end.ToString(config.DateFormat),
                config.CompressionCodec,
                config.MessageSize,
                config.BatchSize,
                totalMBSent,
                totalMBSent / elapsedSecs,
                totalMessagesSent.Get(),
                totalMessagesSent.Get() / elapsedSecs);
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            var config = new ProducerPerfConfig(args);
            if (!config.IsFixedSize)
            {
                Logger.Warn("Throughput will be slower due to changing message size per request");
            }

            var totalBytesSent = new AtomicLong(0);
            var totalMessagesSent = new AtomicLong(0);

            var allDone = new CountdownEvent(config.NumThreads);

            var start = DateTime.Now;
            var rand = new Random();

            if (!config.HideHeader)
            {
                Console.WriteLine("start.time, end.time, compression, message.size, batch.size, total.data.sent.in.MB, MB.sec, " +
                        "total.data.sent.in.nMsg, nMsg.sec");
            }

            for (var i = 0; i < config.NumThreads; i++)
            {
                new Thread(() => new ProducerThread(i, config, totalBytesSent, totalMessagesSent, allDone, rand).Run()).Start();
            }

            allDone.Wait();
            var end = DateTime.Now;
            var elapsedSecs = (end - start).TotalSeconds;
            var totalMBSent = (totalBytesSent.Get() * 1.0) / (1024 * 1024);
            Console.WriteLine(
                "{0}; {1}; {2}; {3}; {4}; {5:f2}; {6:f4}; {7}; {8:f4}",
                start.ToString(config.DateFormat),
                end.ToString(config.DateFormat),
                config.CompressionCodec,
                config.MessageSize,
                config.BatchSize,
                totalMBSent,
                totalMBSent / elapsedSecs,
                totalMessagesSent.Get(),
                totalMessagesSent.Get() / elapsedSecs);
        } 
Exemplo n.º 4
0
        public ProducerThread(int threadId, ProducerPerfConfig config, AtomicLong totalBytesSent, AtomicLong totalMessagesSent, CountdownEvent allDone, Random rand)
        {
            this.threadId = threadId;
            this.config = config;
            this.totalBytesSent = totalBytesSent;
            this.totalMessagesSent = totalMessagesSent;
            this.allDone = allDone;
            this.rand = rand;

            this.producerConfig = new ProducerConfig();

            this.producerConfig.Brokers =
                config.BrokerList.Split(',')
                      .Select(
                          (s, idx) =>
                          new BrokerConfiguration
                              {
                                  BrokerId = idx,
                                  Host = s.Split(':')[0],
                                  Port = int.Parse(s.Split(':')[1])
                              }).ToList();

            this.producerConfig.CompressionCodec = config.CompressionCodec;
            
            this.producerConfig.SendBufferBytes = 64 * 1024;
            if (!config.IsSync)
            {
                this.producerConfig.ProducerType = ProducerTypes.Async;
                this.producerConfig.BatchNumMessages = config.BatchSize;
                this.producerConfig.QueueEnqueueTimeoutMs = -1;
            }
            
            this.producerConfig.ClientId = "ProducerPerformance";
            this.producerConfig.RequestRequiredAcks = config.ProducerRequestRequiredAcks;
            this.producerConfig.RequestTimeoutMs = config.ProducerRequestTimeoutMs;
            this.producerConfig.MessageSendMaxRetries = config.ProducerNumRetries;
            this.producerConfig.RetryBackoffMs = config.ProducerRetryBackoffMs;
            
            this.producerConfig.Serializer = typeof(DefaultEncoder).AssemblyQualifiedName;
            this.producerConfig.KeySerializer = typeof(NullEncoder<long>).AssemblyQualifiedName;
            
            this.producer = new Producer<long, byte[]>(this.producerConfig);

            this.messagesPerThread = config.NumMessages / config.NumThreads;
            Logger.DebugFormat("Messages per thread = {0}", this.messagesPerThread);
        }