<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Simon Brown - Java category</title>
  <link>http://www.simongbrown.com/blog/categories/java/</link>
  <description>Coding the architecture</description>
  <language>en</language>
  <copyright>Simon Brown</copyright>
  <lastBuildDate>Tue, 06 May 2008 13:33:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Building high volume, low latency systems with Java</title>
    <link>http://www.simongbrown.com/blog/2008/05/06/building_high_volume_low_latency_systems_with_java.html</link>
    
      
        <description>
          &lt;p&gt;
For those of you not fortunate enough to be jetting over
to San Francisco for JavaOne this week, feel free to come and join us this evening for some community buzz at the &lt;a href=&#034;http://www.codingthearchitecture.com/pages/londonusergroup.html&#034;&gt;Coding the Architecture London User Group&lt;/a&gt;. Tonight, we&#039;ll be looking at the architecture behind a
Java-based low latency/high volume system.
&lt;/p&gt;

&lt;p&gt;
You can find more details &lt;a href=&#034;http://www.codingthearchitecture.com/2008/04/25/london_user_group_may_2008.html&#034;&gt;here&lt;/a&gt; and you can register &lt;a href=&#034;http://skillsmatter.com/event/java-jee/coding-the-architecture-user-group-meeting&#034;&gt;here&lt;/a&gt;. See you there.
&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://www.simongbrown.com/blog/2008/05/06/building_high_volume_low_latency_systems_with_java.html#comments</comments>
    <guid isPermaLink="true">http://www.simongbrown.com/blog/2008/05/06/building_high_volume_low_latency_systems_with_java.html</guid>
    <pubDate>Tue, 06 May 2008 13:33:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Thinking in aspects</title>
    <link>http://www.simongbrown.com/blog/2008/02/12/thinking_in_aspects.html</link>
    
      
        <description>
          &lt;p&gt;
AOP has proven itself as a very useful technique for centralising the cross-cutting concerns of an application and many of us use aspects in our day to day work, but are people thinking in aspects yet?
&lt;/p&gt;

&lt;p&gt;
For example, frameworks like Spring use aspects under the covers to implement things like support for transactions, but effectively this is all hidden away from the developer. What I&#039;m interested to know is whether people are explicitly designing aspects into their software. Based upon my own experience, I&#039;ve not seen many instances where this has been done; where developers have made a concious decision to use aspects to solve a particular problem. Are your experiences the same?
&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://www.simongbrown.com/blog/2008/02/12/thinking_in_aspects.html#comments</comments>
    <guid isPermaLink="true">http://www.simongbrown.com/blog/2008/02/12/thinking_in_aspects.html</guid>
    <pubDate>Tue, 12 Feb 2008 12:21:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Millisecond accuracy in Java</title>
    <link>http://www.simongbrown.com/blog/2007/08/20/millisecond_accuracy_in_java.html</link>
    
      
        <description>
          &lt;p&gt;
I&#039;m about to start a short consulting engagement where we need to performance test a low latency trading system. By low latency, I mean that messages need to flow through the system in under 50ms.
&lt;/p&gt;

&lt;p&gt;
Performance testing work throws up lots of potential issues such as whether you can get access to accurate timestamps, whether system clocks are synchronised, etc. Another such issue is whether you can measure the time taken to make a request in an accurate way.
&lt;/p&gt;

&lt;p&gt;
Let&#039;s say that you want to measure the time taken to make a synchronous request to a remote resource and measure how long that request takes. Additionally, let&#039;s say that you want to do this under load, simulating various numbers of concurrent users/sessions. One technical solution to this problem is to use something like &lt;a href=&#034;http://jakarta.apache.org/jmeter/&#034;&gt;JMeter&lt;/a&gt; to graph the response times across a varying load. Alternatively, you could write something bespoke. However you do it, you need to be sure that you can measure time as accurately as possible.
&lt;/p&gt;

&lt;p&gt;
If you&#039;re writing a test harness in Java, you can use &lt;code&gt;System.currentTimeMillis()&lt;/code&gt; or &lt;code&gt;System.nanoTime()&lt;/code&gt; (Java 5) to get an accurate measurement of the current time. However, if you&#039;re going to do this, it&#039;s worth reading the Javadocs for each of these methods because they don&#039;t guarantee millisecond accuracy. From &lt;a href=&#034;http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()&#034;&gt;System.currentTimeMillis()&lt;/a&gt; :
&lt;/p&gt;

&lt;blockquote&gt;
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
&lt;/blockquote&gt;

&lt;p&gt;
So how accurate is it? On Windows, &lt;code&gt;System.currentTimeMillis()&lt;/code&gt; doesn&#039;t give you the current time to an exact 1ms resolution because of &lt;a href=&#034;http://www.lochan.org/2005/keith-cl/useful/win32time.html&#034;&gt;the way that the Windows system clock works&lt;/a&gt;. To demonstrate this, I wrote a simple Java program (&lt;a href=&#034;http://www.simongbrown.com/blog/files/clock-accuracy.jar&#034;&gt;download as an executable JAR file&lt;/a&gt;) that collects the current time for a short period and then displays a consolidated view of the results. The output below shows the raw time in milliseconds, the human formatted version, the number of times &lt;code&gt;System.currentTimeMills()&lt;/code&gt; returned that same time and the delta from the previous time.
&lt;/p&gt;

&lt;pre class=&#034;codeSample&#034;&gt;
raw=1187645263093 | formatted=20-Aug-2007 22:27:43:093 | frequency=107567 | delta=15ms
raw=1187645263109 | formatted=20-Aug-2007 22:27:43:109 | frequency=107808 | delta=16ms
raw=1187645263125 | formatted=20-Aug-2007 22:27:43:125 | frequency=103450 | delta=16ms
raw=1187645263140 | formatted=20-Aug-2007 22:27:43:140 | frequency=231928 | delta=15ms
raw=1187645263156 | formatted=20-Aug-2007 22:27:43:156 | frequency=229545 | delta=16ms
&lt;/pre&gt;

&lt;p&gt;
As you can see, Windows tends to provide a clock resolution of about 15ms. I ran this on a couple of reasonably spec&#039;d Windows XP and Windows Server 2003 boxes, and using the Sun and BEA JVMs. However, running the same program on Redhat (2.6.9 kernel) and Mac OS  X (10.4.x, PPC G4 and Intel Core Duo) gave the following results.
&lt;/p&gt;

&lt;pre class=&#034;codeSample&#034;&gt;
raw=1187645137371 | formatted=20-Aug-2007 22:25:37:371 | frequency=3302 | delta=1ms
raw=1187645137372 | formatted=20-Aug-2007 22:25:37:372 | frequency=3282 | delta=1ms
raw=1187645137373 | formatted=20-Aug-2007 22:25:37:373 | frequency=3295 | delta=1ms
raw=1187645137374 | formatted=20-Aug-2007 22:25:37:374 | frequency=2272 | delta=1ms
raw=1187645137375 | formatted=20-Aug-2007 22:25:37:375 | frequency=3293 | delta=1ms
&lt;/pre&gt;

&lt;p&gt;
These simple tests show that some platforms do provide millisecond accuracy. &lt;code&gt;System.nanoTime()&lt;/code&gt; is an alternative but this has it&#039;s own *additional* problems - I&#039;ve found the actual call to be slower and the time returned is relative to a &lt;a href=&#034;http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#nanoTime()&#034;&gt;fixed but arbitrary time&lt;/a&gt;. My initial reaction was that Java is no good for performance testing, but I take that back and make the following recommendations instead.
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you need to measure latencies in a &#034;low latency&#034; system, you need to do this on a platform that has an accurate clock resolution. Check your platform does provide millisecond accuracy before you start testing.&lt;/li&gt;
&lt;li&gt;Don&#039;t try to measure accurate response times/latencies on the Windows platform, unless you&#039;ve &lt;a href=&#034;http://www.lochan.org/2005/keith-cl/useful/win32time.html&#034;&gt;tweaked your OS&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Don&#039;t use Windows to generate load if part of your test data/request includes a millisecond accurate timestamp that you want to pass around the system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
Basically, don&#039;t use Windows. ;-)
&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://www.simongbrown.com/blog/2007/08/20/millisecond_accuracy_in_java.html#comments</comments>
    <guid isPermaLink="true">http://www.simongbrown.com/blog/2007/08/20/millisecond_accuracy_in_java.html</guid>
    <pubDate>Mon, 20 Aug 2007 21:11:00 GMT</pubDate>
  </item>
  
  </channel>
</rss>
