This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch nouveau-ibrowse-improvements
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit d04b46024501a3f96e874e03a3f70055bc720e39
Author: Robert Newson <[email protected]>
AuthorDate: Fri Sep 1 18:31:08 2023 +0100

    bypass ibrowse load balancing
---
 src/docs/src/config/query-servers.rst     | 10 ---------
 src/nouveau/src/nouveau_api.erl           | 15 ++++++++++++-
 src/nouveau/src/nouveau_index_manager.erl | 37 -------------------------------
 3 files changed, 14 insertions(+), 48 deletions(-)

diff --git a/src/docs/src/config/query-servers.rst 
b/src/docs/src/config/query-servers.rst
index 285bf1280..50618b3cd 100644
--- a/src/docs/src/config/query-servers.rst
+++ b/src/docs/src/config/query-servers.rst
@@ -259,16 +259,6 @@ CouchDB's experimental search subsystem can be configured 
via the
         The URL to a running nouveau server. Defaults to
         ``http://127.0.0.1:8080``.
 
-    .. config:option:: max_sessions :: Maximum number of ibrowse sessions
-
-        Nouveau will configure ibrowse max_sessions to this value for
-        the configured ``url``.  Defaults to ``100``.
-
-    .. config:option:: max_pipeline_size :: Max pipeline size
-
-        Nouveau will configure ibrowse max_pipeline_size to this value
-        for the configured ``url``.  Defaults to ``1000``.
-
 .. _config/mango:
 
 Mango
diff --git a/src/nouveau/src/nouveau_api.erl b/src/nouveau/src/nouveau_api.erl
index 39cc2b32f..6f98cf032 100644
--- a/src/nouveau/src/nouveau_api.erl
+++ b/src/nouveau/src/nouveau_api.erl
@@ -32,6 +32,7 @@
 ]).
 
 -define(JSON_CONTENT_TYPE, {"Content-Type", "application/json"}).
+-define(NOUVEAU_CONN_PID, nouveau_conn_pid).
 
 analyze(Text, Analyzer) when
     is_binary(Text), is_binary(Analyzer)
@@ -251,7 +252,19 @@ send_if_enabled(Url, Header, Method) ->
 send_if_enabled(Url, Header, Method, Body) ->
     case nouveau:enabled() of
         true ->
-            ibrowse:send_req(Url, Header, Method, Body);
+            ibrowse:send_req_direct(conn_pid(), Url, Header, Method, Body);
         false ->
             {error, nouveau_not_enabled}
     end.
+
+conn_pid() ->
+    case erlang:get(?NOUVEAU_CONN_PID) of
+        undefined ->
+            Url = nouveau_util:nouveau_url(),
+            {ok, Pid} = ibrowse:spawn_link_worker_process(Url),
+            erlang:put(?NOUVEAU_CONN_PID, Pid),
+            Pid;
+        Pid when is_pid(Pid) ->
+            true = is_process_alive(Pid),
+            Pid
+    end.
diff --git a/src/nouveau/src/nouveau_index_manager.erl 
b/src/nouveau/src/nouveau_index_manager.erl
index bfbd74990..fd925c9ec 100644
--- a/src/nouveau/src/nouveau_index_manager.erl
+++ b/src/nouveau/src/nouveau_index_manager.erl
@@ -19,7 +19,6 @@
 
 -module(nouveau_index_manager).
 -behaviour(gen_server).
--behaviour(config_listener).
 -include("nouveau.hrl").
 
 %% public api
@@ -36,9 +35,6 @@
     handle_info/2
 ]).
 
-% config_listener api
--export([handle_config_change/5, handle_config_terminate/3]).
-
 -export([handle_db_event/3]).
 
 -define(BY_DBSIG, nouveau_by_dbsig).
@@ -60,8 +56,6 @@ init(_) ->
     ets:new(?BY_DBSIG, [set, named_table]),
     ets:new(?BY_REF, [set, named_table]),
     couch_event:link_listener(?MODULE, handle_db_event, nil, [all_dbs]),
-    configure_ibrowse(nouveau_util:nouveau_url()),
-    ok = config:listen_for_changes(?MODULE, nil),
     {ok, nil}.
 
 handle_call({update, #index{} = Index0}, From, State) ->
@@ -119,9 +113,6 @@ handle_info({'DOWN', IndexerRef, process, _Pid, Reason}, 
State) ->
             end,
             {noreply, State}
     end;
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {noreply, State};
 handle_info(_Msg, State) ->
     {noreply, State}.
 
@@ -131,31 +122,3 @@ handle_db_event(DbName, deleted, State) ->
     {ok, State};
 handle_db_event(_DbName, _Event, State) ->
     {ok, State}.
-
-handle_config_change("nouveau", "url", URL, _Persist, State) ->
-    configure_ibrowse(URL),
-    {ok, State};
-handle_config_change(_Section, _Key, _Value, _Persist, State) ->
-    {ok, State}.
-
-handle_config_terminate(_Server, stop, _State) ->
-    ok;
-handle_config_terminate(_Server, _Reason, _State) ->
-    erlang:send_after(
-        5000,
-        whereis(?MODULE),
-        restart_config_listener
-    ).
-
-configure_ibrowse(URL) ->
-    #{host := Host, port := Port} = uri_string:parse(URL),
-    ibrowse:set_max_sessions(
-        Host,
-        Port,
-        config:get_integer("nouveau", "max_sessions", 100)
-    ),
-    ibrowse:set_max_pipeline_size(
-        Host,
-        Port,
-        config:get_integer("nouveau", "max_pipeline_size", 1000)
-    ).

Reply via email to