[ 
https://issues.apache.org/jira/browse/KAFKA-1359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13974561#comment-13974561
 ] 

Guozhang Wang commented on KAFKA-1359:
--------------------------------------

I did a small benchmark on my mac laptop and linux desktop:

{code}
 public class NanoVsMillis {
     public static void main(String[] args) {
         int count = 10 * 1000 * 1000;
         long[] times = new long[count];
         long t1 = System.nanoTime();
         for (int i = 0; i < count; i++) {
             times[i] = System.nanoTime();
         }
         long t2 = System.nanoTime();
         for (int i = 0; i < count; i++) {
             times[i] = System.currentTimeMillis();
         }
         long t3 = System.nanoTime();
         System.out.println("Total time nano : " + ((t2 - t1) / (1000 * 1000)) 
+ "ms");
         System.out.println("Total time millis: " + ((t3 - t2) / (1000 * 1000)) 
+ "ms");
         System.out.println("");
         System.out.println("Avg time nano : " + ((t2 - t1) / count) + "ns");
         System.out.println("Avg time millis: " + ((t3 - t2) / count) + "ns");
     }
 }
{code}

On the mac laptop, since "the QueryPerformanceCounter/ 
QueryPerformanceFrequency API is available, nanoTime actually returns 
currentTimeMillis\*10\^6). ", the results are

{code}
Total time nano : 366ms
Total time millis: 354ms

Avg time nano : 36ns
Avg time millis: 35ns
{code}

On the linux machine, the results are

{code}
Total time nano : 520ms
Total time millis: 470ms

Avg time nano : 52ns
Avg time millis: 47ns
{code}

So I think nanoTime will be a bit more expensive than millis on the linux box. 
If millis' accuracy is sufficient for us, maybe we should switch from nano?

> Add topic/broker metrics once new topic/broker is discovered
> ------------------------------------------------------------
>
>                 Key: KAFKA-1359
>                 URL: https://issues.apache.org/jira/browse/KAFKA-1359
>             Project: Kafka
>          Issue Type: Sub-task
>          Components: producer 
>            Reporter: Guozhang Wang
>            Assignee: Guozhang Wang
>             Fix For: 0.8.2
>
>         Attachments: KAFKA-1359.patch, KAFKA-1359_2014-04-10_10:11:40.patch, 
> KAFKA-1359_2014-04-11_14:20:45.patch, KAFKA-1359_2014-04-16_09:53:55.patch
>
>
> Today some topic/broker level metrics are only added the first time such an 
> event (record-retry, record-error, etc) happens. This has a potential issue 
> for customized mbean reporter which needs to register all the sensors at the 
> time the new broker/topic is discovered. It is better to add such metrics at 
> the very beginning when new topic/brokers are discovered.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to