the8472 / mldht

Bittorrent Mainline DHT implementation in java
Mozilla Public License 2.0
147 stars 45 forks source link

NetworkInterface.getNetworkInterfaces() hoovering up CPU #24

Closed parg closed 5 years ago

parg commented 5 years ago

As I discovered a long time back in Vuze this method can suck up a lot of CPU - see

https://github.com/BiglySoftware/BiglyBT/blob/master/core/src/com/biglybt/core/util/NetUtils.java

getAvailableGloballyRoutableAddrs() is being called every second (multi-homed IPv6 case) and my somewhat hacky tracing shows a significant drop in CPU uage when removed:

[09:54:53] Thread state: elapsed=10000,cpu=1920,max=mldht plugin(1030/10%),mem:max=7431168,tot=947200,free=691956 [09:55:03] Thread state: elapsed=10000,cpu=1886,max=mldht plugin(1061/10%),mem:max=7431168,tot=947200,free=574934 [09:55:13] Thread state: elapsed=10000,cpu=1714,max=mldht plugin(1155/11%),mem:max=7431168,tot=947200,free=534988 [09:55:23] Thread state: elapsed=10000,cpu=1794,max=mldht plugin(1076/10%),mem:max=7431168,tot=947200,free=494851 [09:55:33] Thread state: elapsed=10000,cpu=1766,max=mldht plugin(1154/11%),mem:max=7431168,tot=947200,free=464217 [09:55:43] Thread state: elapsed=10000,cpu=1715,max=mldht plugin(874/8%),mem:max=7431168,tot=947200,free=433772 [09:55:53] Thread state: elapsed=10063,cpu=1779,max=mldht plugin(936/9%),mem:max=7431168,tot=938496,free=793216 [09:56:03] Thread state: elapsed=10000,cpu=529,max=mldht DISABLED AFTER THIS LOG plugin(187/1%),mem:max=7431168,tot=938496,free=668896 [09:56:13] Thread state: elapsed=10000,cpu=343,max=mldht plugin(124/1%),mem:max=7431168,tot=938496,free=623921 [09:56:23] Thread state: elapsed=10000,cpu=327,max=mldht plugin(110/1%),mem:max=7431168,tot=938496,free=589410

the8472 commented 5 years ago

I guess that's mostly a windows problem? I have a linux box with hundreds of IP addresses and it barely shows up in profiles.

But yeah, I can add some timimg and automatic backoff.

the8472 commented 5 years ago

Try e79ff01443cf4b3c62e3d0320cb00f5744f10999, it should reduce the frequency of that call by 20x

parg commented 5 years ago

Definitely an improvement, thanks