13

Does anyone have recommendation for setting optimal buffer size for JSP's? You can use the following page directive to set the buffer size in JSP's

    <%@page buffer="xxxkb" autoFlush="true" %>

My questions are the following

  1. My understanding is that the less buffer size that you use, the performance is better for client side browsers. Does my assumption correct? If you think otherwise, please explain

  2. What should be the optimal buffer size

  3. Is there a way to know what is the default buffer size?

  4. Setting autoflush to true should flush the buffer once the max size reached. If you set it to false, its upto you to decide when to flush

webjockey
  • 1,647
  • 2
  • 20
  • 28
  • I did some performance testing based on buffer size. It looks like 5K buffer size performs pretty well. I see that the browser is receiving constant response stream to work with. This shows noticeable faster response rendering on the browser. – webjockey Apr 05 '15 at 20:32

1 Answers1

16

1.My understanding is that the less buffer size that you use, the performance is better for client side browsers. Does my assumption correct? If you think otherwise, please explain

Answer: Yes, not actually in terms of performance. But in terms of rendering the content. Because the client will get data at faster rate. Buffer size should be greater than or equal to the underlying socket buffer size. Otherwise, though the jsp's flushes when the buffer size is reached it will not be actually written to the client.

2.What should be the optimal buffer size

Answer: As I have said above it should be greater than or equal the underlying socket buffer size. The optimal size also depends on your application. It should be such a value that once the buffer size is reached, the response will be committed and you can no more do operation which result in adding response header.

3.Is there a way to know what is the default buffer size?

Answer : Yes , by using JspWriter class. JspWriter has a getter getBufferSize() which gives you the buffer size. The JspWriter can be obtained using pageContext.getOut().

4.Setting autoflush to true should flush the buffer once the max size reached. If you set it to false, its upto you to decide when to flush

Answer: If set to true, it will flush when the max buffer size is reached. If set to false, it will throw an exception

Rohit Gaikwad
  • 3,677
  • 3
  • 17
  • 40
Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50
  • But how could we know the underlying socket buffer size? – Y.L. Jun 24 '14 at 08:33
  • 1
    @CyberRusher late answer but just landed here today. See http://stackoverflow.com/q/7865069/837154 – orique Aug 21 '14 at 09:36
  • I know this is old, but the first answer is just plain wrong. It says performance is better but also performance is not better. It says that the client gets the data at a faster rate, which is patently false. The rate at which the client receives the data is dependent upon how fast the server supplies it and how fast the network is between them. The only thing that changes is _latency_, which is a different concept. – Christopher Schultz Mar 12 '20 at 21:24