diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2011-06-28 17:48:21 -0700 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2012-04-11 13:45:59 -0700 |
commit | dace50628c5acc0aad94538eb6d3bd31e055d941 (patch) | |
tree | f6bef53b628fafeba459fd8e83e4057c0982deb9 /test/find-connect-limit | |
parent | f63d616bc048fe256181ff5e7e4aaca11afe3237 (diff) | |
download | luasocket-dace50628c5acc0aad94538eb6d3bd31e055d941.tar.gz luasocket-dace50628c5acc0aad94538eb6d3bd31e055d941.tar.bz2 luasocket-dace50628c5acc0aad94538eb6d3bd31e055d941.zip |
Utility to find how many TCP connections can be made.
Diffstat (limited to 'test/find-connect-limit')
-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 | |||