Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Commit b76dcb2

Browse files
committed
Track open time without using process dictionary
We were only removing the `{async_open, DbName}` process dictionary entries if the open is successful. Over time, in busy situations, the process dictionary can grow very large. COUCHDB-2749
1 parent b3d1028 commit b76dcb2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/couch_server.erl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ maybe_close_lru_db(#server{lru=Lru}=Server) ->
302302

303303
open_async(Server, From, DbName, Filepath, Options) ->
304304
Parent = self(),
305-
put({async_open, DbName}, os:timestamp()),
305+
T0 = os:timestamp(),
306306
Opener = spawn_link(fun() ->
307307
Res = couch_db:start_link(DbName, Filepath, Options),
308308
case {Res, lists:member(create, Options)} of
@@ -311,7 +311,7 @@ open_async(Server, From, DbName, Filepath, Options) ->
311311
_ ->
312312
ok
313313
end,
314-
gen_server:call(Parent, {open_result, DbName, Res}, infinity),
314+
gen_server:call(Parent, {open_result, T0, DbName, Res}, infinity),
315315
unlink(Parent)
316316
end),
317317
ReqType = case lists:member(create, Options) of
@@ -345,13 +345,11 @@ handle_call({set_max_dbs_open, Max}, _From, Server) ->
345345
{reply, ok, Server#server{max_dbs_open=Max}};
346346
handle_call(get_server, _From, Server) ->
347347
{reply, {ok, Server}, Server};
348-
handle_call({open_result, DbName, {ok, Db}}, {FromPid, _Tag}, Server) ->
348+
handle_call({open_result, T0, DbName, {ok, Db}}, {FromPid, _Tag}, Server) ->
349349
link(Db#db.main_pid),
350350
true = ets:delete(couch_dbs_pid_to_name, FromPid),
351-
case erase({async_open, DbName}) of undefined -> ok; T0 ->
352-
OpenTime = timer:now_diff(os:timestamp(), T0) / 1000,
353-
couch_stats:update_histogram([couchdb, db_open_time], OpenTime)
354-
end,
351+
OpenTime = timer:now_diff(os:timestamp(), T0) / 1000,
352+
couch_stats:update_histogram([couchdb, db_open_time], OpenTime),
355353
% icky hack of field values - compactor_pid used to store clients
356354
% and fd used to possibly store a creation request
357355
[#db{fd=ReqType, compactor_pid=Froms}] = ets:lookup(couch_dbs, DbName),
@@ -372,9 +370,9 @@ handle_call({open_result, DbName, {ok, Db}}, {FromPid, _Tag}, Server) ->
372370
Server#server.lru
373371
end,
374372
{reply, ok, Server#server{lru = Lru}};
375-
handle_call({open_result, DbName, {error, eexist}}, From, Server) ->
376-
handle_call({open_result, DbName, file_exists}, From, Server);
377-
handle_call({open_result, DbName, Error}, {FromPid, _Tag}, Server) ->
373+
handle_call({open_result, T0, DbName, {error, eexist}}, From, Server) ->
374+
handle_call({open_result, T0, DbName, file_exists}, From, Server);
375+
handle_call({open_result, _T0, DbName, Error}, {FromPid, _Tag}, Server) ->
378376
% icky hack of field values - compactor_pid used to store clients
379377
[#db{fd=ReqType, compactor_pid=Froms}=Db] = ets:lookup(couch_dbs, DbName),
380378
[gen_server:reply(From, Error) || From <- Froms],

0 commit comments

Comments
 (0)