You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2022/07/27 14:09:21 UTC

[GitHub] [couchdb-ioq] iilyak commented on a diff in pull request #21: Add IOQ2 pid for search traffic

iilyak commented on code in PR #21:
URL: https://github.com/apache/couchdb-ioq/pull/21#discussion_r931111610


##########
src/ioq_sup.erl:
##########
@@ -40,8 +42,10 @@ init([]) ->
     }}.
 
 ioq_server2_children() ->
+    Name = ?IOQ2_SEARCH_SERVER,
+    Search = {Name, {ioq_server2, start_link, [Name, search, false]}, permanent, 5000, worker, [Name]},

Review Comment:
   I've noticed that you are using `re:` module to filter the processes you need. I have a suggestion how to improve that. In erlang's supervisor the child id is not necessary an atom, it is any term. Which means you can encode the type of a child (or scheduler number) into the child id. In this case you can switch from using strings to using atoms. Matching on atoms would speed up the filter_children function a lot.
   
   
   ```
   
   
   ioq_server2_children() ->
       Name = ?IOQ2_SEARCH_SERVER,
       Search = {{ioq2, Name}, {ioq_server2, start_link, [Name, search, false]}, permanent, 5000, worker, [Name]},
       Bind = config:get_boolean("ioq2", "bind_to_schedulers", false),
       [Search | ioq_server2_children(erlang:system_info(schedulers), Bind)].
   
   ioq_server2_children(Count, Bind) ->
       lists:map(fun(I) ->
           Name = list_to_atom("ioq_server_" ++ integer_to_list(I)),
           {{ioq2, Name}, {ioq_server2, start_link, [Name, I, Bind]}, permanent, 5000, worker, [Name]}
       end, lists:seq(1, Count)).
   
   processes(ioq2) ->
       filter_children(ioq2);
   processes(ioq) ->
       filter_children(ioq_server);
   processes(config_listener_mon) ->
       filter_children(config_listener_mon);
   processes(Arg) ->
       {error, [
           {expected_one_of, [ioq, ioq2, config_listener_mon]},
           {got, Arg}]}.
   
   filter_children(Kind) ->
       lists:filtermap(fun({ChildId, P, _, _}) ->
           case ChildId of
               Kind -> {true, {ChildId, P}};
               {Kind, Id} -> {true, {Id, P}}
               _ -> false
           end
       end, supervisor:which_children(?MODULE)).
   ```
   
   
     



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org