> Just count accepted connections and every, say, 1000th

> connection check current time, if less than a second

> elapsed since previous check, close the listening socket.

Then you risk killing genuine traffic. Above average hit from a handful of locations is more likely to be abuse.

> Isn't ddos caused by packet congestion rather than server

> processing?

From what I understand, a DDoS attack any pat of your system, usually the part that is the slowest. You want to kill attacking traffic as quickly as possible without affecting genuine traffic. As for attacks on the network itself, this is where you rely on your cloud service provider.