arriven / db1000n

MIT License
1.18k stars 208 forks source link

Performance + protocol fixes #535

Closed deputinizer closed 2 years ago

deputinizer commented 2 years ago

Description

Performance fixes + HTTP 1.1 protocol fix.

Fixes

Type of change

Tested

Tested with pprof CPU profile (svg command).

ubuntu@pc:~$ ./db1000n -pprof :6060 -log-level debug 2> logs.txt
...
ubuntu@pc:~$ go tool pprof http://localhost:6060/debug/pprof/profile?seconds=60

Logs

So i've added some more dialing debug (not in commits :smiley: ) Multiple HTTP requests on one connection proves that #534 is correct

grep -v "dial tcp" logs.txt > logs_no_dial.txt

With resp.SkipBody = true

single fasthttp job request {"atomic_id": 1452, "target": "https://kim.tektorg.ru/"}
dialing {"addr": "kim.tektorg.ru:443"}
single fasthttp job request {"atomic_id": 1453, "target": "https://kim.tektorg.ru/"}
dialing {"addr": "kim.tektorg.ru:443"}
single fasthttp job request {"atomic_id": 1454, "target": "https://fin.tektorg.ru/bg"}
dialing {"addr": "fin.tektorg.ru:443"}
single fasthttp job request {"atomic_id": 1455, "target": "https://fin.tektorg.ru/bg"}
dialing {"addr": "fin.tektorg.ru:443"}
single fasthttp job request {"atomic_id": 1456, "target": "https://fin.tektorg.ru/bg"}
dialing {"addr": "fin.tektorg.ru:443"}
single fasthttp job request {"atomic_id": 1457, "target": "https://fin.tektorg.ru/bg"}
dialing {"addr": "fin.tektorg.ru:443"}
single fasthttp job request {"atomic_id": 1458, "target": "https://fin.tektorg.ru/bg"}
dialing {"addr": "fin.tektorg.ru:443"}
single fasthttp job request {"atomic_id": 1459, "target": "https://fin.tektorg.ru/bg"}
dialing {"addr": "fin.tektorg.ru:443"}

With resp.SkipBody = false

single fasthttp job request {"atomic_id": 1358, "target": "https://kim.tektorg.ru/"}
single fasthttp job request {"atomic_id": 1359, "target": "https://kim.tektorg.ru/"}
single fasthttp job request {"atomic_id": 1360, "target": "https://www.tektorg.ru/"}
single fasthttp job request {"atomic_id": 1361, "target": "https://kim.tektorg.ru/"}
single fasthttp job request {"atomic_id": 1362, "target": "https://irao.tektorg.ru/"}
single fasthttp job request {"atomic_id": 1363, "target": "https://irao.tektorg.ru/"}
single fasthttp job request {"atomic_id": 1364, "target": "https://www.tektorg.ru/"}
single fasthttp job request {"atomic_id": 1365, "target": "https://www.tektorg.ru/"}

As you can see SkipBody == true breaks the protocol and makes TLS handshakes constantly after every single HTTP request.

Screenshots

deputinizer commented 2 years ago

Lol why use lint :sob: Lint disallows this and self

deputinizer commented 2 years ago
[Spoiler] We can make DNS resolver use almost 0% CPU ![image](https://user-images.githubusercontent.com/100740281/167231444-7365abaa-1587-4347-a520-3cddd0442646.png)
deputinizer commented 2 years ago
[Spoiler] Works. ![image](https://user-images.githubusercontent.com/100740281/167231678-a250e5fe-b349-4c80-934f-843cd5cdc228.png) However, I think this linter thing is bullshit
deputinizer commented 2 years ago

Also, stoppropaganda + db1000n authors should do some collab and on rewriting the whole thing in Rust.

deputinizer commented 2 years ago

These templates are not entirely necessary...

Spoiler: pprof memory ![image](https://user-images.githubusercontent.com/100740281/167232338-294c882a-8176-4721-ad03-63ff33745e67.png)
deputinizer commented 2 years ago

Probably fixed #528

deputinizer commented 2 years ago

Ok since @Arriven commited changes already, I'm closing due to merge conflicts.

roman-kruglov commented 2 years ago

maybe just rebase, I'm sure there isn't a lot of conflicts