3 ms·
What does the loop and sleep 1 do? Is that to respawn upon crashes (why'd it crash?) or does it exit socat after handling a request? I recently made a netcat w
by Aachen 3y ago
What does the loop and sleep 1 do? Is that to respawn upon crashes (why'd it crash?) or does it exit socat after handling a request?
I recently made a netcat webserver returning only one static response just to have a tiny info page for my new email server, that needs a while true loop but no sleep. I then benchmarked the performance and was very surprised to find that a slow VPS manages [spoiler answer] https://lgms.nl/p/cau/?b64&bY%2FBTsQwDER%2FZbivViDxAxw58Q1pOtkEWrvEzu7y97gFceJkjT3zbL9d2fH8iM7PQXPDFtqYVWa0gi8dqGldo9kct%2BYVFB2Xirw0itsDXsK5aie8JsHT%2F6gj%2BT7MocLf7BmvwZ7B%2B8bsnJFCylzGguSYAnGCNcncVws5G1zRh8QmYkpWsahuJ%2BTK%2FGEo2o8J782ce05LMEtbjtscPrrYYTH2%2FW8t5bRrgW3pFrNwdwZX6DkCW9dMs5%2F03wVTi4ei7qBNuyNdUpPzNw%3D%3D https://lgms.nl/p/cau/?b64&bY%2FBTsQwDER%2FZbivViDxAxw58Q1pO... Performance graph: https://snipboard.io/Vtn0MO.jpg https://snipboard.io/Vtn0MO.jpg
- tyingq 3y agoIt's a one-shot awk script. Handle one request and exit.
- Aachen 3y agoHuh okay, then why the sleep?! That kills performance but why'd you do that
- tyingq 3y agoNo idea, not my script. Socat does support this kind of syntax, which would seem better suited in this case. socat -v -v TCP-LISTEN:8080,reuseaddr,fork SYSTEM:/some/script It also has a settable max-children so you can put some bounds on it. I did post another comment where I shared my gawk webserver, but I'm not using socat.
- Crestwave 3y agoThe sleep is probably to prevent endless revival of the script when you try to cancel it with Ctrl-C. But yeah, it's not ideal considering you can't make more than one request within a second.
- Aachen 3y agoCould if [ -f /tmp/dontrespawn ]; then break; fi Instead of sleeping, you can create that file when you want it to stop. But perhaps that'd imply that someone would genuinely use this rather than only developing it as a toy
- deleted 3y ago[deleted]