summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-02-01 06:47:32 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-02-01 06:47:32 +0000
commit9f0ae92b4f4c0762214092cf8d50675d01c847ab (patch)
treeb833c6b60d5cd91950ab6b6c47e53966e751b238
parent7d139047706621e21cb73ffc2dc238be8f03db48 (diff)
Backport COUCHDB-1008 from trunk (revision 1055592)
The motivation for this backport is to prevent the "nodelay" option, under section "httpd", from reaching version 1.1. This patch introduces the "socket_options" configuration parameter which is more generic - it allows nodelay as well as other socket options to be specified. Not adding this patch to 1.1.x would imply still supporting the "nodelay" parameter in future releases to avoid breaking the configuration API. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1065922 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--etc/couchdb/default.ini.tpl.in4
-rw-r--r--etc/couchdb/local.ini5
-rw-r--r--src/couchdb/couch_httpd.erl21
3 files changed, 25 insertions, 5 deletions
diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
index e8a69f77..882ca4f6 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/etc/couchdb/default.ini.tpl.in
@@ -20,6 +20,10 @@ default_handler = {couch_httpd_db, handle_request}
secure_rewrites = true
vhost_global_handlers = _utils, _uuids, _session, _oauth, _users
allow_jsonp = false
+; Options for the MochiWeb HTTP server.
+;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
+; For more socket options, consult Erlang's module 'inet' man page.
+;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
[ssl]
port = 6984
diff --git a/etc/couchdb/local.ini b/etc/couchdb/local.ini
index 1c4060ab..33380a32 100644
--- a/etc/couchdb/local.ini
+++ b/etc/couchdb/local.ini
@@ -10,6 +10,11 @@
[httpd]
;port = 5984
;bind_address = 127.0.0.1
+; Options for the MochiWeb HTTP server.
+;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
+; For more socket options, consult Erlang's module 'inet' man page.
+;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
+
; Uncomment next line to trigger basic-auth popup on unauthorized requests.
;WWW-Authenticate = Basic realm="administrator"
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index dc98957c..47d2edb7 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -57,8 +57,6 @@ start_link(Name, Options) ->
% will restart us and then we will pick up the new settings.
BindAddress = couch_config:get("httpd", "bind_address", any),
- NoDelay = "true" == couch_config:get("httpd", "nodelay", "false"),
-
DefaultSpec = "{couch_httpd_db, handle_request}",
DefaultFun = make_arity_1_fun(
couch_config:get("httpd", "default_handler", DefaultSpec)
@@ -82,7 +80,17 @@ start_link(Name, Options) ->
UrlHandlers = dict:from_list(UrlHandlersList),
DbUrlHandlers = dict:from_list(DbUrlHandlersList),
DesignUrlHandlers = dict:from_list(DesignUrlHandlersList),
+ {ok, ServerOptions} = couch_util:parse_term(
+ couch_config:get("httpd", "server_options", "[]")),
+ {ok, SocketOptions} = couch_util:parse_term(
+ couch_config:get("httpd", "socket_options", "[]")),
Loop = fun(Req)->
+ case SocketOptions of
+ [] ->
+ ok;
+ _ ->
+ ok = mochiweb_socket:setopts(Req:get(socket), SocketOptions)
+ end,
apply(?MODULE, handle_request, [
Req, DefaultFun, UrlHandlers, DbUrlHandlers, DesignUrlHandlers
])
@@ -90,11 +98,10 @@ start_link(Name, Options) ->
% and off we go
- {ok, Pid} = case mochiweb_http:start(Options ++ [
+ {ok, Pid} = case mochiweb_http:start(Options ++ ServerOptions ++ [
{loop, Loop},
{name, Name},
- {ip, BindAddress},
- {nodelay,NoDelay}
+ {ip, BindAddress}
]) of
{ok, MochiPid} -> {ok, MochiPid};
{error, Reason} ->
@@ -109,6 +116,10 @@ start_link(Name, Options) ->
?MODULE:stop();
("httpd", "default_handler") ->
?MODULE:stop();
+ ("httpd", "server_options") ->
+ ?MODULE:stop();
+ ("httpd", "socket_options") ->
+ ?MODULE:stop();
("httpd_global_handlers", _) ->
?MODULE:stop();
("httpd_db_handlers", _) ->