tags:

views:

69

answers:

3

It seems to be pretty fast already and i was just wondering if anyone knows if its using NIO. I tried searching the whole source code for NIO (well, its kind of way to search :) lol); but did not hit anything. Also, If its not using NIO; do you think its worthwhile to modify log4j to use NIO also to make it more faster? Any pointers advises and links to some resources would be lot helpful.

+2  A: 

Check out the FileAppender source. Pretty much just standard java.io.

krock
Thanks for the source. Is it worth to implement a NIO appender equivalent to these ones? Will it make it faster?
Aviator
No. NIO is non-blocking IO as opposed to the one-thread-per-connection model in Java's standard IO. It's not about speed.
hbunny
@stevendick: I was thinking about RandomAccessFile with FileChannel and MBB. Won't it help a little? :(
Aviator
+2  A: 

Also, If its not using NIO; do you think its worthwhile to modify of log4j to use NIO also to make it more faster?

No, unless logging is a significant part of your application's activities, in which case there is usually something wrong.

You seem to be under the impression that NIO 'is faster', but this is not true in general. Just try creating two files, one with standard IO and one with NIO, writing a bunch of data to them and closing them. You'll see the performance hardly differs. NIO will only perform better in certain use cases; most usually the case of many connections.

Confusion
Yes; these are significant part of application in one mode and i want that mode also to be better performing. I am writing from a single application so i am not sure how to associate connections here. May be can i compare it to number of threads trying to write something to log? If so; yes there are lot of threads trying to write something. I know that writing a lot into log from application is not the best solutionl; but i just want to make sure its not the worst :) too. Thanks a lot for insights. I will try comparing IO and NIO myself with some examples.
Aviator
+1  A: 

I don't see any reason why FileChannel could be any faster than FileOutputStream in this case.

maybe by using MappedByteBuffer? but in append mode, the behavior is OS dependent.

ultimately, the performance depends on your hard drive, your code matters very little.

irreputable
Yes I was thinking about MBBs only. Thats why i asked this question itself! Thanks! Will keep these points in mind.
Aviator