-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from emqtt/esockd3
eSockd3
- Loading branch information
Showing
27 changed files
with
513 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: erlang | ||
|
||
otp_release: | ||
- 17.0 | ||
|
||
script: | ||
- make | ||
|
||
sudo: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
|
||
# eSockd | ||
# eSockd [](https://travis-ci.org/emqtt/esockd) | ||
|
||
Erlang General Non-blocking TCP/SSL Socket Server. | ||
|
||
## Features | ||
|
||
General Non-blocking TCP/SSL Socket Server. | ||
|
||
Acceptor Pool and Asynchronous TCP Accept. | ||
|
||
Max connections management. | ||
|
||
Allow/Deny by peer address. | ||
|
||
Keepalive Support. | ||
|
||
## Benchmark | ||
|
||
Benchmark 2.1.0-alpha release on one 8 cores, 32G memory ubuntu/14.04 server from qingcloud.com: | ||
|
||
``` | ||
250K concurrent connections, 50K messages/sec, 40Mbps In/Out consumed 5G memory, 20% CPU/core | ||
``` | ||
* General Non-blocking TCP/SSL Socket Server | ||
* Acceptor Pool and Asynchronous TCP Accept | ||
* Parameterized Connection Module | ||
* Max connections management | ||
* Allow/Deny by peer address | ||
* Keepalive Support | ||
* Rate Limit | ||
|
||
## Usage | ||
|
||
|
@@ -32,24 +22,24 @@ A Simple Echo Server: | |
|
||
-export([start_link/1]). | ||
|
||
start_link(SockArgs) -> | ||
{ok, spawn_link(?MODULE, init, [SockArgs])}. | ||
start_link(Conn) -> | ||
{ok, spawn_link(?MODULE, init, [Conn])}. | ||
|
||
init(SockArgs = {Transport, _Sock, _SockFun}) -> | ||
{ok, NewSock} = esockd_connection:accept(SockArgs), | ||
loop(Transport, NewSock, state). | ||
|
||
loop(Transport, Sock, State) -> | ||
case Transport:recv(Sock, 0) of | ||
{ok, Data} -> | ||
{ok, Name} = Transport:peername(Sock), | ||
io:format("~p: ~s~n", [Name, Data]), | ||
Transport:send(Sock, Data), | ||
loop(Transport, Sock, State); | ||
{error, Reason} -> | ||
io:format("tcp ~s~n", [Reason]), | ||
{stop, Reason} | ||
end. | ||
init(Conn) -> | ||
{ok, NewConn} = Conn:wait(), | ||
loop(NewConn). | ||
|
||
loop(Conn) -> | ||
case Conn:recv(0) of | ||
{ok, Data} -> | ||
{ok, PeerName} = Conn:peername(), | ||
io:format("~s - ~s~n", [esockd_net:format(peername, PeerName), Data]), | ||
Conn:send(Data), | ||
loop(Conn); | ||
{error, Reason} -> | ||
io:format("tcp ~s~n", [Reason]), | ||
{stop, Reason} | ||
end. | ||
``` | ||
|
||
Startup Echo Server: | ||
|
@@ -81,7 +71,7 @@ examples/ | |
|
||
Example | Description | ||
----------|------ | ||
async_recv| prim_net async recv | ||
async_recv| prim_net async recv/send | ||
gen_server| gen_server behaviour | ||
simple | simple echo server | ||
ssl | ssl echo server | ||
|
@@ -122,6 +112,7 @@ Options: | |
{access, [esockd_access:rule()]} | | ||
{logger, atom() | {atom(), atom()}} | | ||
{ssl, [ssl:ssloption()]} | | ||
{connopts, [{rate_limit, string()}]} | | ||
{sockopts, [gen_tcp:listen_option()]}. | ||
``` | ||
|
||
|
@@ -212,11 +203,20 @@ Logger option: | |
esockd:open(echo, 5000, [{logger, {error_logger, info}}], {echo_server, start_link, []}). | ||
``` | ||
|
||
## Benchmark | ||
|
||
Benchmark 2.1.0-alpha release on one 8 cores, 32G memory ubuntu/14.04 server from qingcloud.com: | ||
|
||
``` | ||
250K concurrent connections, 50K messages/sec, 40Mbps In/Out consumed 5G memory, 20% CPU/core | ||
``` | ||
|
||
## License | ||
|
||
The MIT License (MIT) | ||
|
||
## Author | ||
|
||
[email protected] | ||
Feng Lee <[email protected]> | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICuTCCAiICCQC8+3PPaqATfDANBgkqhkiG9w0BAQUFADCBoDELMAkGA1UEBhMC | ||
Q0gxETAPBgNVBAgTCFpoZUppYW5nMREwDwYDVQQHEwhIYW5nWmhvdTEUMBIGA1UE | ||
ChMLWGlhb0xpIFRlY2gxHzAdBgNVBAsTFkluZm9ybWF0aW9uIFRlY2hub2xvZ3kx | ||
EzARBgNVBAMTCnQuZW1xdHQuaW8xHzAdBgkqhkiG9w0BCQEWEGZlbmcgYXQgZW1x | ||
dHQuaW8wHhcNMTUwMjI1MTc0NjQwWhcNMTYwMjI1MTc0NjQwWjCBoDELMAkGA1UE | ||
BhMCQ0gxETAPBgNVBAgTCFpoZUppYW5nMREwDwYDVQQHEwhIYW5nWmhvdTEUMBIG | ||
A1UEChMLWGlhb0xpIFRlY2gxHzAdBgNVBAsTFkluZm9ybWF0aW9uIFRlY2hub2xv | ||
Z3kxEzARBgNVBAMTCnQuZW1xdHQuaW8xHzAdBgkqhkiG9w0BCQEWEGZlbmcgYXQg | ||
ZW1xdHQuaW8wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALAtN2OHsvltOk+9 | ||
AtlwMtKuaWW2WpV/S0lRRG9x9k8pyd5PJeeYAr2jVsoWnZInb1CoEOHFcwxZLjv3 | ||
gEvz+X+//W02YyI9hnvCJUpT/+6P0gJEbmTmqL078M6vbtwtiF1YC7mdo0nGAZuK | ||
qedpIoEZbVJavf4S0vXWTsb3s5unAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAgUR3 | ||
z4uDUsAl+xUorPMBIOS/ncHHVk1XucVv9Wi4chzzZ+4/Y77/fFqP6oxhQ59C9Q8i | ||
iT5wjaE4R1eCge18lPSw3yb1tsTe5B3WkRTzziPq/Q/AsC+DifkkE1YW67leuJV/ | ||
vz74sEi0dudmOVoe6peYxjEH8xXoIUqhnwXt/4Q= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIICXAIBAAKBgQCwLTdjh7L5bTpPvQLZcDLSrmlltlqVf0tJUURvcfZPKcneTyXn | ||
mAK9o1bKFp2SJ29QqBDhxXMMWS4794BL8/l/v/1tNmMiPYZ7wiVKU//uj9ICRG5k | ||
5qi9O/DOr27cLYhdWAu5naNJxgGbiqnnaSKBGW1SWr3+EtL11k7G97ObpwIDAQAB | ||
AoGBAKU1cbiLG0GdtU3rME3ZUj+RQNMZ4u5IVcBmTie4FcN8q4ombKQ2P3O4RX3z | ||
IUZaZp+bS2F8uHt+8cVYPl57Zp5fwbIlv6jWgGpvXLsX8JBQl2OTw38B+hVwJvAM | ||
h0mBzprUOs3KGZyF5cyA4osrZ4QvCZhwId9fAjwLGBF9i1yBAkEA4jWAF1sWQiwF | ||
vY476m+0ihpRwGKjldKHWFZmvoB/AnNV/rXO+HRl3MB5wmO+Dqg3gJZrjGBgDeaV | ||
g9hoQjK6ZwJBAMdg57iKLd8uUb7c4pR8fDdDbeeI5X7WDf2k9emT3BMPJPQ3EiSf | ||
CStn1hRfp31U9CXEnw94rKHhrdMFrYjdzMECQCcWD3f5qTLt4GAMf5XWj199hLq1 | ||
UIbGxdQhuccY9Nk7jJRiXczYb/Fg4KkSCvkFX/G8DAFJdc9xFEyfzAQEN+kCQH3a | ||
nMrvZn9gBLffRKOIZPyZctHZp0xGIHTA4X39GMlrIN+Lt8coIKimlgssSlSiAK+q | ||
iuFAQnC5PXlcNyuTHsECQAMNMY6jXikgSUZfVXitAFX3g9+IbjT9eJ92f60QneW8 | ||
mxWQoqP3fqCSbTEysb7NojEEwppSZtaNgnBb5R4E+mU= | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.