0

Is there a way I can set the send buffer size for the HTTP listener/response sockets created by Tomcat or Jetty? (ie. SO_SNDBUF). Apologies if I'm getting the terminology wrong.

Update:

After googling around and with @Joakim's help I found this:

http://wiki.eclipse.org/Jetty/Howto/Configure_Connectors

and

Slow transfers in Jetty with chunked transfer encoding at certain buffer size

The question then is are the "buffer size" referred by the Jetty.xml config as well as the HttpServletResponse.setBufferSize() the same as the socket "send buffer size"?

Update 2:

Reading more I think neither affect the socket buffer size and its just another buffer the servlet container uses before sending it over to the Socket.

Community
  • 1
  • 1
Justin Khoo
  • 3,261
  • 3
  • 15
  • 13

2 Answers2

1

In Jetty 9 with spring it can be done with:

@Configuration

public class CustomJettyConfiguration {

@Bean
public EmbeddedServletContainerCustomizer customizer() {
    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof JettyEmbeddedServletContainerFactory) {
                customizeJetty((JettyEmbeddedServletContainerFactory) container);
            }
        }

        private void customizeJetty(JettyEmbeddedServletContainerFactory jetty) {
            jetty.addServerCustomizers(new JettyServerCustomizer() {

                @Override
                public void customize(Server server) {
                    for (Connector connector : server.getConnectors()) {
                        if (connector instanceof ServerConnector) {
                            HttpConnectionFactory connectionFactory = ((ServerConnector) connector)
                                    .getConnectionFactory(HttpConnectionFactory.class);
                            connectionFactory.getHttpConfiguration()
                                    .setResponseHeaderSize(16 * 1024);
                        }
                    }
                }
            });
        }
    };

}

}

gil
  • 181
  • 8
0

Jetty has no support for Socket.setSendBufferSize() in any version of Jetty.

You can however, provide your own implementation of a Connector to do just that.

Start by extending SocketConnector in which you provide your own .configure(Socket) implementation that does Socket.setSendBufferSize(int).

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Thanks Joakim! Does this allow me to replace the HTTP listener that Jetty uses with my own implementation of the Connector? – Justin Khoo Jan 04 '13 at 00:04
  • It sure would, you can be as complicated as you want to. Start with looking at the open source code for the various connectors to see what will best suit your needs. – Joakim Erdfelt Jan 04 '13 at 04:25
  • Much appreciated @Joakim. Searching on Google, would this be the method to replace the default connector with my own implementation? http://www.eclipse.org/jetty/documentation/current/configuring-connectors.html – Justin Khoo Jan 04 '13 at 09:34
  • You linked to Jetty 9 documentation (currently in Milestones/Beta's), a far more complicated beast. Where we have to contend with TLS/SPDY/WebSocket/HTTP2.0 protocol upgrade/negotiation issues. Jetty 9 also has no blocking socket implementation anymore. Simply setting the Socket.setSendBufferSize() on all accepted sockets could (maybe) be problematic as you don't (yet) know what the protocol is. Try out what you want with Jetty 7 or 8 (stable/mature) to see if you really want that feature. – Joakim Erdfelt Jan 04 '13 at 13:13