1

I am trying to implement a HTTP server using netty & i wanted to know few thing which i could not understand from the netty api. I read many other netty related stackoverflow question but still i couldn't udnertand.

1.If i want the connection from client to be opened for a certain period of time, what should i use CONNECT_TIMEOUT_MILLIS or add a read timeout handler & add a timeout in it. Basically i want to understand the difference between these two. & what is the default value of CONNECT_TIMEOUT_MILLIS.

  1. what is the default value of SO_BACKLOG,i read it in one of the that it is equal to SOMAXCONN in io.netty.netUtils.But what it the value of it. Also, i want to be sure that so_backlog limits the number of worker thread ri8?. I mean if i set it to say 1000 it means netty won't allow more than 1000 open connection at a time.

  2. can somebody explain how netty responds to a HTTP request as in internally in terms of writing & reading from a channel?

Thanks in advance!!!

Caesar
  • 179
  • 2
  • 3
  • 10

2 Answers2

6

CONNECT_TIMEOUT_MILLIS is the timeout for connection attempt. Once the connection is established, it has no effect. What you are interested in is ReadTimeoutHandler.

The default SO_BACKLOG is NetUtils.SOMAXCONN. It does not limit the number of worker threads. For more information about SO_BACKLOG, please refer to this question. To limit the number of worker threads, you must specify it when you construct an NioEventLoop. SO_BACKLOG is unrelated to the maximum number of concurrent connections, either.

Re: How HTTP works in Netty - The question is too broad to give a simple answer. Please use your debugger to step into the Netty internals to find our how it works.

Community
  • 1
  • 1
trustin
  • 12,231
  • 6
  • 42
  • 52
  • thanks for the reply. So what should i use to limit the number of concurrent clients connecting to my server. Earlier i thought tha maybe if i limit the number of worker threads i mi8 be able to control the number of conucrrent connections but since u say that is not the case. can you suggest a way to limit the maximum number of concurrent connections – Caesar Apr 16 '14 at 06:23
  • I would comment that SOMAXCONN is a poorly chosen default. It guarantees maximum resource utilization where it should use the platform default, or Java's, which are both more sensibly chosen. – user207421 Apr 16 '14 at 06:33
0

One way of limiting the number of concurrent connections is by limiting the number of open files a process can have. This property can be set in Linux using ulimit command or using limits.conf file

SaiVikas
  • 162
  • 1
  • 12