i m working with kafka, and i made a producer like that:

  while (true){

            long start = Instant.now().toEpochMilli();
            for (int i=0; i< NUM_MSG_SEC  ; i++)
            {

                PriceStreamingData data = PriceStreamingData.newBuilder()
                        .setUser(getRequest().getUser())
                        .setSecurity(getRequest().getSecurity())
                        .setTimestamp(Instant.now().toEpochMilli())
                        .setPrice(new Random().nextDouble()*200)
                        .build();


                record = new ProducerRecord<>(topic, keyBuilder.build(data),
                        data);



                producer.send(record,new Callback(){
                    @Override
                    public void onCompletion(RecordMetadata arg0,
Exception arg1) {
                        counter.incrementAndGet();
                        if(arg1 != null){
                            arg1.printStackTrace();
                        }


                    }
                });

            }
            long diffCiclo = Instant.now().toEpochMilli() - start;
            long diff = Instant.now().toEpochMilli() - startTime;


            System.out.println("Number of sent: " + counter.get() +
                    " Millisecond:" + (diff) + " -
NumberOfSent/Diff(K): " + counter.get()/diff );

            try {
                if(diffCiclo >= 1000){
                    System.out.println("over 1 second: "  + diffCiclo);

                }
                else {
                    obj.wait( 1000 - diffCiclo );

                }
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }




        }


as you can see it is extremely simple, it just make a new message and
send it. If i see the logs:

    NumberOfSent/Diff(K)

in the first 10 seconds it perform very bad just

  30k per second

after 60 seconds i have

  180k  per second

why ? and how can i already start the process going already to 180k ?

Reply via email to