High CPU utilization with large HOSTS file #4180

Closed
opened 2026-02-21 17:10:51 -05:00 by deekerman · 2 comments
Owner

Originally created by @B16EC302BEFB051D45025E3342E81C on GitHub (Apr 15, 2016).

Setup: Win7 64bit / qB 3.3.4 (QT 5.6.0, libtorrent 1.0.8.0, boost 1.60.0)
DNS Cache service disabled.

the hosts file is ~ 12MB; it has lots of entries for malware,tracking,etc.
i noticed high CPU utilization when either:
a) torrents are started
b) torrents are stopped

there are 97 torrents. 92 are seeding.

high CPU util will go on for a while, and then settle down. i've seen it last for 10min.
another problem is that when exiting qB, it'll hang (no UI, but qbittorrent.exe process present) until this thread is finished.

i looked at it with sysinternals:procmon and noticed that it's continually reading the HOSTS file. i also noticed that the HOSTS file is locked, alas cannot be renamed.

i then used sysinternals:procexp. i noticed that one thread has high CPU utilization: 25% of quad-core system. picture below.

qb_12mb-hosts-threads

thread stack dump is below:

DNSAPI.dll!DnsQueryConfig+0x970
DNSAPI.dll!HostsFile_ReadLine+0x5e
DNSAPI.dll!DnsFreeConfigStructure+0x1398
DNSAPI.dll!NetInfo_Copy+0x456
DNSAPI.dll!DnsValidateName_W+0xa5
DNSAPI.dll!NetInfo_Copy+0x6e4
DNSAPI.dll!Query_Main+0xad
DNSAPI.dll!DnsUpdateMachinePresence+0x5ab
DNSAPI.dll!DnsUpdateMachinePresence+0x4cf
DNSAPI.dll!DnsQueryExW+0xed
DNSAPI.dll!DnsQueryExW+0x96
DNSAPI.dll!DnsQueryExW+0x39
MSWSOCK.dll+0x4ed3
MSWSOCK.dll+0x4d5f
MSWSOCK.dll+0x4b43
WS2_32.dll!FreeAddrInfoW+0x198
WS2_32.dll!FreeAddrInfoW+0x178
WS2_32.dll!WSALookupServiceNextW+0xff
WS2_32.dll!WSALookupServiceNextW+0x6a
WS2_32.dll!WSALookupServiceNextW+0x4a4
WS2_32.dll!WSALookupServiceNextW+0x273
WS2_32.dll!WSALookupServiceBeginW+0xb1b
WS2_32.dll!GetAddrInfoW+0x210
WS2_32.dll!getaddrinfo+0x6d
qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x674b2b
qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x673bcb
qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x676f40
qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x676b75
qbittorrent.exe!?write@engine@detail@ssl@asio@boost@@QAE?AW4want@12345@ABVconst_buffer@45@AAVerror_code@system@5@AAI@Z+0x110c3f
ntdll.dll!RtlInitializeExceptionChain+0x63
ntdll.dll!RtlInitializeExceptionChain+0x36

next i paused all torrents; exited the program, and ran it again; still with the 12MB HOSTS file. waited a few seconds and then started the torrents. the snapshot below is of the performance graph after about 7 minutes:

qb_12mb-hosts

the blue I/O graph is the sum of all read activity. peak around 52MB.

next i disabled "Resolve peer host names". paused. exit. reran qB. restart torrents. no change in performance/behavior:

qb_12mb-hosts-noresolve

next i paused all torrents then exited qB. renamed the 12MB HOSTS file, and used a much smaller 2KB HOSTS file instead. (note: this can not be done while qB is running since it locks the HOSTS file). the problem is resolved. no high CPU util, and no frantic reading of the HOSTS file.

i toggled between the 12MB and 2KB HOSTS file 3 times. each attempt was similar. pictures below are from each attempt with the 2KB HOSTS file.

Attempt #1:
qb_2kb-hosts-1

Attempt #2:
qb_2kb-hosts-2

Attempt #3:
qb_2kb-hosts-3

note that the I/O in the 3rd attempt peaked at 3.8MB.


workaround: this is not entirely qB related, but it does work for those that wish to use a large HOSTS file. it speeds up the DNS queries as well. i prefer it over the windows DNS cache.

  1. install Acrylic DNS Proxy
  2. configure Acrylic to point to your regular DNS servers
  3. move your large HOSTS file to {Acrylic Directory}/AcrylicHosts.txt
  4. reserve the windows HOSTS file for a smaller personal set, which will take effect immediately upon saving and you won't have to restart the Acrylic service
  5. statically set interface DNS server to 127.0.0.1
Originally created by @B16EC302BEFB051D45025E3342E81C on GitHub (Apr 15, 2016). Setup: Win7 64bit / qB 3.3.4 (QT 5.6.0, libtorrent 1.0.8.0, boost 1.60.0) DNS Cache service disabled. the hosts file is ~ 12MB; it has lots of entries for malware,tracking,etc. i noticed high CPU utilization when either: a) torrents are started b) torrents are stopped there are 97 torrents. 92 are seeding. high CPU util will go on for a while, and then settle down. i've seen it last for 10min. another problem is that when exiting qB, it'll hang (no UI, but qbittorrent.exe process present) until this thread is finished. i looked at it with [sysinternals:procmon](https://technet.microsoft.com/en-us/sysinternals/processmonitor) and noticed that it's continually reading the HOSTS file. i also noticed that the HOSTS file is locked, alas cannot be renamed. i then used [sysinternals:procexp](https://technet.microsoft.com/en-us/sysinternals/processexplorer). i noticed that one thread has high CPU utilization: 25% of quad-core system. picture below. ![qb_12mb-hosts-threads](https://cloud.githubusercontent.com/assets/18488068/14577289/0d84e15c-0340-11e6-9d8f-f287409c92bb.jpg) thread stack dump is below: > DNSAPI.dll!DnsQueryConfig+0x970 > DNSAPI.dll!HostsFile_ReadLine+0x5e > DNSAPI.dll!DnsFreeConfigStructure+0x1398 > DNSAPI.dll!NetInfo_Copy+0x456 > DNSAPI.dll!DnsValidateName_W+0xa5 > DNSAPI.dll!NetInfo_Copy+0x6e4 > DNSAPI.dll!Query_Main+0xad > DNSAPI.dll!DnsUpdateMachinePresence+0x5ab > DNSAPI.dll!DnsUpdateMachinePresence+0x4cf > DNSAPI.dll!DnsQueryExW+0xed > DNSAPI.dll!DnsQueryExW+0x96 > DNSAPI.dll!DnsQueryExW+0x39 > MSWSOCK.dll+0x4ed3 > MSWSOCK.dll+0x4d5f > MSWSOCK.dll+0x4b43 > WS2_32.dll!FreeAddrInfoW+0x198 > WS2_32.dll!FreeAddrInfoW+0x178 > WS2_32.dll!WSALookupServiceNextW+0xff > WS2_32.dll!WSALookupServiceNextW+0x6a > WS2_32.dll!WSALookupServiceNextW+0x4a4 > WS2_32.dll!WSALookupServiceNextW+0x273 > WS2_32.dll!WSALookupServiceBeginW+0xb1b > WS2_32.dll!GetAddrInfoW+0x210 > WS2_32.dll!getaddrinfo+0x6d > qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x674b2b > qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x673bcb > qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x676f40 > qbittorrent.exe!?impl@context@ssl@asio@boost@@QAEPAUssl_ctx_st@@XZ+0x676b75 > qbittorrent.exe!?write@engine@detail@ssl@asio@boost@@QAE?AW4want@12345@ABVconst_buffer@45@AAVerror_code@system@5@AAI@Z+0x110c3f > ntdll.dll!RtlInitializeExceptionChain+0x63 > ntdll.dll!RtlInitializeExceptionChain+0x36 next i paused all torrents; exited the program, and ran it again; still with the 12MB HOSTS file. waited a few seconds and then started the torrents. the snapshot below is of the performance graph after about 7 minutes: ![qb_12mb-hosts](https://cloud.githubusercontent.com/assets/18488068/14577286/0d8282f4-0340-11e6-96fd-a22f19cfbffa.jpg) the blue I/O graph is the sum of all read activity. peak around 52MB. next i disabled "Resolve peer host names". paused. exit. reran qB. restart torrents. no change in performance/behavior: ![qb_12mb-hosts-noresolve](https://cloud.githubusercontent.com/assets/18488068/14577285/0d825fae-0340-11e6-82a9-b2b3dbe9a526.jpg) next i paused all torrents then exited qB. renamed the 12MB HOSTS file, and used a much smaller 2KB HOSTS file instead. (note: this can not be done while qB is running since it locks the HOSTS file). the problem is resolved. no high CPU util, and no frantic reading of the HOSTS file. i toggled between the 12MB and 2KB HOSTS file 3 times. each attempt was similar. pictures below are from each attempt with the 2KB HOSTS file. Attempt #1: ![qb_2kb-hosts-1](https://cloud.githubusercontent.com/assets/18488068/14577288/0d842e4c-0340-11e6-9c16-e2b01d7f6622.jpg) Attempt #2: ![qb_2kb-hosts-2](https://cloud.githubusercontent.com/assets/18488068/14577287/0d827a34-0340-11e6-9cb6-8a3c460db948.jpg) Attempt #3: ![qb_2kb-hosts-3](https://cloud.githubusercontent.com/assets/18488068/14577284/0d81ea60-0340-11e6-81f0-438cfa4abd8a.jpg) note that the I/O in the 3rd attempt peaked at 3.8MB. --- workaround: this is not entirely qB related, but it does work for those that wish to use a large HOSTS file. it speeds up the DNS queries as well. i prefer it over the windows DNS cache. 1. install Acrylic DNS Proxy 2. configure Acrylic to point to your regular DNS servers 3. move your large HOSTS file to {Acrylic Directory}/AcrylicHosts.txt 4. reserve the windows HOSTS file for a smaller personal set, which will take effect immediately upon saving and you won't have to restart the Acrylic service 5. statically set interface DNS server to 127.0.0.1
Author
Owner

@B16EC302BEFB051D45025E3342E81C commented on GitHub (Apr 16, 2016):

probably same as (or related to) #5097

@B16EC302BEFB051D45025E3342E81C commented on GitHub (Apr 16, 2016): probably same as (or related to) #5097
Author
Owner

@ngosang commented on GitHub (Sep 16, 2018):

We are closing all issues related to old qBittorrent versions (qBittorrent < 4.1.0).
Please, update to last release and, if the bug/error/crash is still present, open another issue.
Thank you.

@ngosang commented on GitHub (Sep 16, 2018): We are closing all issues related to old qBittorrent versions (qBittorrent < 4.1.0). Please, update to last release and, if the bug/error/crash is still present, open another issue. Thank you.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/qBittorrent#4180
No description provided.