diff options
| -rwxr-xr-x | test/find-connect-limit | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/find-connect-limit b/test/find-connect-limit new file mode 100755 index 0000000..ad0c3f5 --- /dev/null +++ b/test/find-connect-limit | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #!/usr/bin/env lua | ||
| 2 | --[[ | ||
| 3 | Find out how many TCP connections we can make. | ||
| 4 | |||
| 5 | Use ulimit to increase the max number of descriptors: | ||
| 6 | |||
| 7 | ulimit -n 10000 | ||
| 8 | ulimit -n | ||
| 9 | |||
| 10 | You'll probably need to be root to do this. | ||
| 11 | ]] | ||
| 12 | |||
| 13 | require "socket" | ||
| 14 | |||
| 15 | host = arg[1] or "google.com" | ||
| 16 | port = arg[2] or 80 | ||
| 17 | |||
| 18 | connections = {} | ||
| 19 | |||
| 20 | repeat | ||
| 21 | c = assert(socket.connect(hostip or host, 80)) | ||
| 22 | table.insert(connections, c) | ||
| 23 | |||
| 24 | if not hostip then | ||
| 25 | hostip = c:getpeername() | ||
| 26 | print("resolved", host, "to", hostip) | ||
| 27 | end | ||
| 28 | |||
| 29 | print("connection #", #connections, c, "fd", c:getfd()) | ||
| 30 | |||
| 31 | until false | ||
| 32 | |||
