You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by sana qadir <q5...@yahoo.com> on 2008/07/08 05:18:06 UTC

RE: precision of log4j

Thanks Micheal, I do get better resolution timing now J
 
I am also trying to time how long it takes a particular message to travel from identical machines A to B. That is propagation time = receive time – sent time. I cannot use System.nanoTime(); in this case and the resolution of System.currentTimeMillis() (i.e. 15.625ms) is unacceptable:
 
On Machine A:
long sent_time = System.currentTimeMillis();
out.write (msg);
 
On Machine B:
in.read(msg);
long receive_time = System.currentTimeMillis();
 
Despite synchronizing the time on the two machines using NTP, I am getting not only poor resolution but also negative propagation values which are ridiculous. Any idea about how I can get better resolution is this scenario?
 
Regards,
Sana

--- On Tue, 6/24/08, Michael Erskine <mi...@ketech.com> wrote:

From: Michael Erskine <mi...@ketech.com>
Subject: RE: precision of log4j
To: "Log4J Users List" <lo...@logging.apache.org>
Date: Tuesday, June 24, 2008, 4:16 PM

> From: sana qadir [mailto:q57sana@yahoo.com]
> Sent: 24 June 2008 05:40
> Subject: precision of log4j
> I am using log4j to help me record the execution times of several
> functions (1 to n) using code similar to the following snippet:
>
> logger.debug("Timestamp before...");
> function_n();
> logger.debug("Timestamp after...");

OK, Log4J isn't necessarily going to do what you want: if you want high
resolution timings you can use System.nanoTime and to make the timings
accurate, don't corrupt them by logging while you're timing...

long t1 = System.nanoTime();
function_n();
long t2 = System.nanoTime();

logger.debug("duration in nanos: "+(t2 -t1));


Regards,
Michael Erskine.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


      

Re: precision of log4j

Posted by Thorbjørn Ravn Andersen <th...@gmail.com>.
sana qadir skrev  den 08-07-2008 05:18:
> Despite synchronizing the time on the two machines using NTP, I am getting not only poor resolution but also negative propagation values which are ridiculous. Any idea about how I can get better resolution is this scenario
Sounds like you have to do a roundtrip.  A->B->A.

Otherwise you must synchronize both computers to exactly the same time, 
i.e. an external atomic clock.

-- 
  Thorbjørn

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org