tag:blogger.com,1999:blog-6990886.post109147399852167867..comments2023-10-31T20:40:14.812+05:30Comments on Sachin's Java and Software Blog: Experiences In Java Performance EngineeringSachinhttp://www.blogger.com/profile/17218289326440085577noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-6990886.post-1121722363176942042005-07-19T03:02:00.000+05:302005-07-19T03:02:00.000+05:30Knock Knock.Knock Knock.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091974000733458562004-08-08T19:36:00.000+05:302004-08-08T19:36:00.000+05:30Make me a happy person. change your blogger settin...Make me a happy person. change your blogger settings to automatically ping weblogs. Then I'll know when you've updated. I look forward to more posts.ExpatEggheadhttps://www.blogger.com/profile/13578130377226462702noreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091649745224678652004-08-05T01:32:00.000+05:302004-08-05T01:32:00.000+05:30Firstly, thanks to Dion for linking my article her...Firstly, thanks to Dion for linking my article <A HREF="http://www.blogger.com/r?http%3A%2F%2Fwww.theserverside.com%2Fnews%2Fthread.tss%3Fthread_id%3D27773">here</A>. My primary intention was to chronicle my findings while involved in a performance tuning exercise. The effort was focused at brute throughput improvements and therefore involved more low-level tweaking. I would have put more effort into the article if I had known I was addressing an audience of this magnitude :-). So, being a victim of unexpected attention, I think it would be prudent to cover a couple of findings in more detail since quite a few people have mentioned them.<br /><br />I would very strongly agree with people who have mentioned that 'clean' code is much better than 'clever' code. Some of the tunings are potential cases where encapsulation gets broken, code maintainability gets affected. Also, if performance is satisfactory, I would prefer not to go overboard tuning it. Sometimes though, when you are competing with other very similar [standard-based] products, you cannot explain to a potential customer that your code is slower than XYZ because our code is much 'cleaner'.<br /><br />A lot of people have mentioned String.substring* making a reference to the original char array. Yes it does that, there are, however, some useful cases of using the character array and pointers to pieces of data inside it [lets call it a CharBuffer] without using String. Lets take the case of the Web Server again. HTTP request headers are read from the socket's input stream into a buffer. There is no way of creating a String from this buffer without a data copy. Subsequently there is no way to retrieve the character array back from String without a data copy. <br />There are cases where you need to convert the String to a char[] e.g. the request line needs to be written to access logs. CharBuffer saves data copies in these situations. Another situation arises because of the case insensitive nature of HTTP headers. It's cheaper to convert them to lower case or upper case in place and then process the request - again CharBuffer helps.<br /><br />Object pooling does help considerably although it could again be considered as excessive optimization for most software. Although, GC performance has significantly improved version after version, if you really have long lasting allocations like buffers, pooling does help. PrintWriter, like I mentioned in the article, is a different case, where the cost of executing its constructor makes it a good choice for pooling.<br /><br />* for business reasons, our code compiles with JDK 1.3 so I cannot make use of JDK 1.4 features. If some point is redundant as a result of newer classes in JDK 1.4 please bear with me :-)Sachinhttps://www.blogger.com/profile/17218289326440085577noreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091635384311087072004-08-04T21:33:00.000+05:302004-08-04T21:33:00.000+05:30It is possible to write a server without any objec...It is possible to write a server without any object creation, except for the objects Java creates for security checking. How? No matter what your server does, every request uses the same set of objects. Preallocate them, then reuse them. If there are some variations, preallocate the objects required for that too. If there are shared resources (files, db, other tiers) pool them. A server's tasks are very repetitive: there are never surprises, so you never need to use "new".<br /><br />This a server - why do you need Strings? Strings are for humans. Pool char or byte arrays. <br /><br />Are your arrays not exactly the right size? Doesn't matter: Pool big ones, and only use the number of bytes you need. Computers have lots of memory now days.<br /><br />- rpcxdr@yahoo.comAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091580148565872812004-08-04T06:12:00.000+05:302004-08-04T06:12:00.000+05:30Hmm, i thought object creation wasn't that much of...Hmm, i thought object creation wasn't that much of a problem with the new GC.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091577457699511412004-08-04T05:27:00.000+05:302004-08-04T05:27:00.000+05:30StringBuffer's substring() method delegates to Str...StringBuffer's substring() method delegates to String(int,int,char[]) which does, as you say, just refer to the private char[] of the original String. (Incidentally, is this is a potential memory leak if you have long long-lived references to small substrings of large Strings?) I don't doubt Sachin, but I'm curious what causes the performance problems.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091556229310580162004-08-03T23:33:00.000+05:302004-08-03T23:33:00.000+05:30Cool stuff Sachin!Cool stuff Sachin!Ramesh L.https://www.blogger.com/profile/03153867738881886976noreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091555001094514802004-08-03T23:13:00.000+05:302004-08-03T23:13:00.000+05:30Doesn't the StringBuffer (starting with JDK1.2 or ...Doesn't the StringBuffer (starting with JDK1.2 or JDK1.3) use copy-on-write? So, given<br /><br />String s1 = "This is a test";<br />String s2 = s1.substring(3,5);<br /><br />s2 will share its character array with s1. In essense, the String object is already doing what you are recommending to implement with custom string reference objects.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091480800937237672004-08-03T02:36:00.000+05:302004-08-03T02:36:00.000+05:30Well, ordering (or lack thereof) isn't the sole re...Well, ordering (or lack thereof) isn't the sole reason to use Set instead of List. Recall that Set stipulates that no duplicates are allowed whereas List allows dupliates. You should ONLY use a Set where your data is, in fact, a Set and does not contain duplicates.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6990886.post-1091476129676395362004-08-03T01:18:00.000+05:302004-08-03T01:18:00.000+05:30First of, all suck-up aside, it shows that you wor...First of, all suck-up aside, it shows that you work for pramati. Secondly, your simple advice on Set versus List is pure gold!<br /><br />Regarding human perception... the human eye can do about 28 "frames per second", but you have no guarantee that they'll overlap with the refreshes of the CRT. 35-40 miliseconds should be more than enough.Gabriel Mhttps://www.blogger.com/profile/18020403326536585795noreply@blogger.com