Bug 3933 - SocketServer Poor Performance could be improved significantly.
Summary: SocketServer Poor Performance could be improved significantly.
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P3 major
Target Milestone: ---
Assignee: log4j-dev
Depends on:
Reported: 2001-10-02 18:55 UTC by Kok Chong
Modified: 2004-11-16 19:05 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Kok Chong 2001-10-02 18:55:08 UTC
The SockServer performance is extremely poor when a lot of messages (>100/secs)
are sent to the logserver.  The problem could be solved by simply making a 
buffered read from the socket input stream.  

public SocketNode(Socket socket,Hierarchy hierarchy) {
    this.socket = socket;
    this.hierarchy = hierarchy;
    try {
      ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream
    catch(Exception e) {
      cat.error("Could not open ObjectInputStream to "+socket, e);
Comment 1 cgu 2001-10-02 23:01:50 UTC

Thanks for the patch. Have you tried measuring the performance increase? I 
would like to remind you that TCP sockets are intrinsically buffered. Have you 
observed a performance increase? Thanks, Ceki
Comment 2 Kok Chong 2001-10-04 12:25:15 UTC
With BufferedInputStream, the performane improved drastically.  
If you truss -p on the logserver, the read is one character at a time without
it.  With buffered, it's reading a string at a time 
(saving the context switching between read).

Test 1:
Send 100 messages/sec.

Before: 7% CPU
After : 0.17% CPU

Test 2:
Send messages in a loop without sleep.

Before: 90%  after          400 messsages in 40 secs.
After : 60%   received 25,000 messages in 20 secs.
Comment 3 Mark Womack 2002-04-09 22:20:25 UTC
I have to concur with Kok.  I made his suggested improvement in my version of 
Chainsaw (which also uses ServerSocket and ObjectInputStream), and the 
throughput of messages went up dramatically.  I don't have exact numbers but 
there was definitely an increase.
Comment 4 Ceki Gulcu 2002-05-09 12:37:48 UTC
OK. I incorporated the change you suggested altough my tests on Windows could 
not show a difference.