mirror of
https://github.com/btdig/dhtcrawler2.git
synced 2025-02-07 13:59:08 +00:00
try to fix high cpu usage when no hash and no wait_download
This commit is contained in:
parent
91731f7839
commit
eb4f6fa9ea
@ -89,9 +89,13 @@ handle_info(process_download_hash, State) ->
|
|||||||
?T(?FMT("start a new download ~p", [D])),
|
?T(?FMT("start a new download ~p", [D])),
|
||||||
% launch downloader
|
% launch downloader
|
||||||
Conn = db_conn(State),
|
Conn = db_conn(State),
|
||||||
try_next_download(Conn),
|
case try_next_download(Conn) of
|
||||||
% until the max downloader count reaches
|
ok ->
|
||||||
timer:send_after(?DOWNLOAD_INTERVAL, process_download_hash),
|
% until the max downloader count reaches
|
||||||
|
timer:send_after(?DOWNLOAD_INTERVAL, process_download_hash);
|
||||||
|
empty ->
|
||||||
|
skip
|
||||||
|
end,
|
||||||
D % + 1, bug here ?
|
D % + 1, bug here ?
|
||||||
end,
|
end,
|
||||||
{noreply, State#state{downloading = NewD}};
|
{noreply, State#state{downloading = NewD}};
|
||||||
@ -214,7 +218,7 @@ try_next_download(Conn) ->
|
|||||||
check_in_index_cache(Conn, Doc).
|
check_in_index_cache(Conn, Doc).
|
||||||
|
|
||||||
check_in_index_cache(_, {}) ->
|
check_in_index_cache(_, {}) ->
|
||||||
ok;
|
empty;
|
||||||
check_in_index_cache(Conn, {Doc}) ->
|
check_in_index_cache(Conn, {Doc}) ->
|
||||||
{Hash} = bson:lookup(hash, Doc),
|
{Hash} = bson:lookup(hash, Doc),
|
||||||
ListHash = binary_to_list(Hash),
|
ListHash = binary_to_list(Hash),
|
||||||
@ -227,7 +231,8 @@ check_in_index_cache(Conn, {Doc}) ->
|
|||||||
% so give it up
|
% so give it up
|
||||||
hash_reader_stats:handle_cache_filtered(),
|
hash_reader_stats:handle_cache_filtered(),
|
||||||
self() ! filter_torrent
|
self() ! filter_torrent
|
||||||
end.
|
end,
|
||||||
|
ok.
|
||||||
|
|
||||||
should_try_download(true, Conn, Hash) ->
|
should_try_download(true, Conn, Hash) ->
|
||||||
db_hash_index:exist(Conn, Hash);
|
db_hash_index:exist(Conn, Hash);
|
||||||
|
Loading…
Reference in New Issue
Block a user