This is an automated email from the ASF dual-hosted git repository. iilyak pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/couchdb-ioq.git
The following commit(s) were added to refs/heads/master by this push: new 63617af Fix compiler warnings new 103cf1c Merge pull request #10 from cloudant/fix-compilation-warnings 63617af is described below commit 63617af731f72ed9ac4fb8eb5e1100725c59ec34 Author: ILYA Khlopotov <iil...@apache.org> AuthorDate: Wed Feb 20 19:16:14 2019 +0000 Fix compiler warnings - Replace use of `erlang:now/0` with `erlang:monotonic_time/0` - Replace use of `random` module with `rand` module --- src/ioq_osq.erl | 7 +++++-- src/ioq_server.erl | 16 +++++++++------- src/ioq_server2.erl | 20 +++----------------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/ioq_osq.erl b/src/ioq_osq.erl index 2dbfaea..25db3d4 100644 --- a/src/ioq_osq.erl +++ b/src/ioq_osq.erl @@ -42,7 +42,8 @@ start_link() -> call(Pid, Msg, Priority) -> - Reply = gen_server:call(ioq_osq, {rlimit, nil, Priority, now()}, infinity), + Now = erlang:monotonic_time(), + Reply = gen_server:call(ioq_osq, {rlimit, nil, Priority, Now}, infinity), try gen_server:call(Pid, Msg, infinity) after @@ -230,7 +231,9 @@ submit_request(Channel, {{Fd,Call,Pri,T0}, From}, #state{reqs=Reqs} = State) -> record_stats(Channel, Pri, T0) -> IOClass = if is_tuple(Pri) -> element(1, Pri); true -> Pri end, - Latency = timer:now_diff(now(),T0) / 1000, + Now = erlang:monotonic_time(), + Latency = erlang:convert_time_unit( + Now - T0, native, millisecond), catch couch_stats:increment_counter([couchdb, io_queue, IOClass]), catch couch_stats:increment_counter([couchdb, io_queue, osproc]), catch couch_stats:update_histogram([couchdb, io_queue, latency], Latency), diff --git a/src/ioq_server.erl b/src/ioq_server.erl index 8e0891d..e33c2fc 100644 --- a/src/ioq_server.erl +++ b/src/ioq_server.erl @@ -67,7 +67,7 @@ call(Fd, Msg, Priority) -> msg = Msg, channel = Channel, class = Class, - t0 = now() + t0 = erlang:monotonic_time() }, case config:get("ioq.bypass", atom_to_list(Class)) of "true" -> @@ -145,7 +145,7 @@ handle_cast(_Msg, State) -> handle_info({Ref, Reply}, #state{reqs = Reqs} = State) -> case lists:keytake(Ref, #request.ref, Reqs) of {value, #request{from=From} = Req, Reqs2} -> - TResponse = erlang:now(), + TResponse = erlang:monotonic_time(), erlang:demonitor(Ref, [flush]), reply_to_all(From, Reply), update_histograms(ioq_histos, Req, TResponse), @@ -419,8 +419,8 @@ submit_request(Request, State) -> % record some stats RW = rw(Call), - SubmitTime = now(), - Latency = timer:now_diff(SubmitTime, T0) / 1000, + SubmitTime = erlang:monotonic_time(), + Latency = erlang:convert_time_unit(SubmitTime - T0, native, millisecond), catch couch_stats:increment_counter([couchdb, io_queue, IOClass]), catch couch_stats:increment_counter([couchdb, io_queue, RW]), catch couch_stats:update_histogram([couchdb, io_queue, latency], Latency), @@ -432,8 +432,10 @@ update_counter(Tab, Channel, IOClass, RW) -> update_histograms(Tab, Req, TResponse) -> #request{t0=T0, tsub=TSubmit, class=Class, channel=Channel, msg=Msg} = Req, - Delta1 = timer:now_diff(TSubmit, T0), - Delta2 = timer:now_diff(TResponse, TSubmit), + Delta1 = erlang:convert_time_unit( + TSubmit - T0, native, microsecond), + Delta2 = erlang:convert_time_unit( + TResponse - TSubmit, native, microsecond), Bin1 = timebin(Delta1), Bin2 = timebin(Delta2), Bin3 = timebin(Delta1+Delta2), @@ -478,7 +480,7 @@ timebin(V) -> choose_next_request(Qs, Priorities) -> Norm = lists:sum(Priorities), QueuesAndPriorities = lists:zip(Qs, Priorities), - SortedQueues = sort_queues(QueuesAndPriorities, Norm, random:uniform()), + SortedQueues = sort_queues(QueuesAndPriorities, Norm, rand:uniform()), {Item, NewQueues} = choose_prioritized_request(SortedQueues), Map0 = lists:zip(SortedQueues, NewQueues), {Item, [element(2, lists:keyfind(Q, 1, Map0)) || Q <- Qs]}. diff --git a/src/ioq_server2.erl b/src/ioq_server2.erl index 5e2e01f..dadd44d 100644 --- a/src/ioq_server2.erl +++ b/src/ioq_server2.erl @@ -112,8 +112,7 @@ call(Fd, Msg, Dimensions) -> "ioq2", "dispatch_strategy", ?DISPATCH_SERVER_PER_SCHEDULER), Server = case DispatchStrategy of ?DISPATCH_RANDOM -> - maybe_seed(), - SID = random:uniform(erlang:system_info(schedulers)), + SID = rand:uniform(erlang:system_info(schedulers)), ?SERVER_ID(SID); ?DISPATCH_FD_HASH -> NumSchedulers = erlang:system_info(schedulers), @@ -601,19 +600,6 @@ prioritize_request(Req, State) -> end. --spec maybe_seed() -> {integer(), integer(), integer()}. -maybe_seed() -> - case get(random_seed) of - undefined -> - <<A:32, B:32, C:32>> = crypto:strong_rand_bytes(12), - Seed = {A, B, C}, - random:seed(Seed), - Seed; - Seed -> - Seed - end. - - %% ioq_server2 Tests @@ -954,7 +940,7 @@ setup_many(Count, RespDelay) -> ), FakeServer = fun(F) -> receive {'$gen_call', {Pid, Ref}, Call} -> - timer:sleep(random:uniform(RespDelay)), + timer:sleep(rand:uniform(RespDelay)), Pid ! {Ref, {reply, Call}} end, F(F) @@ -1042,7 +1028,7 @@ wait_for_success(Count) when Count > 0 -> random_server(Servers) -> - lists:nth(random:uniform(length(Servers)), Servers). + lists:nth(rand:uniform(length(Servers)), Servers). test_io_error(#state{waiters=Waiters, reqs=Reqs}=State) ->