{"id":17964794,"url":"https://github.com/astronin/sgi","last_synced_at":"2025-07-02T14:04:49.063Z","repository":{"id":57547349,"uuid":"57387762","full_name":"AstRonin/sgi","owner":"AstRonin","description":"Socket Gateway Interface","archived":false,"fork":false,"pushed_at":"2017-04-29T17:03:42.000Z","size":537,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T09:40:43.617Z","etag":null,"topics":["balancer","cluster","cowboy","erlang","fastcgi","multiplexer","n2o","php","python","tor","uwsgi","websocket"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AstRonin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-29T13:47:39.000Z","updated_at":"2025-02-26T14:55:12.000Z","dependencies_parsed_at":"2022-09-26T18:40:51.661Z","dependency_job_id":null,"html_url":"https://github.com/AstRonin/sgi","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AstRonin%2Fsgi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AstRonin%2Fsgi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AstRonin%2Fsgi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AstRonin%2Fsgi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AstRonin","download_url":"https://codeload.github.com/AstRonin/sgi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245413574,"owners_count":20611350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["balancer","cluster","cowboy","erlang","fastcgi","multiplexer","n2o","php","python","tor","uwsgi","websocket"],"created_at":"2024-10-29T12:08:43.920Z","updated_at":"2025-03-25T06:31:01.453Z","avatar_url":"https://github.com/AstRonin.png","language":"Erlang","readme":"# SGI - Socket Gateway Interface\n\nApplication is written on Erlang. General design principles are: fast, low memory and modularity.\n\nSGI gives possibility simple and smart way to connect to any server by [TCP](https://en.wikipedia.org/wiki/Transmission_Control_Protocol)\nand has other protocols working under TCP.\nIt supports two protocols:\n- [FastCGI](https://en.wikipedia.org/wiki/FastCGI). \n    This protocol is common for connect to [PHP (FPM)](http://php.net/manual/en/install.fpm.php).\n- [uwsgi](https://uwsgi-docs.readthedocs.io/en/latest/Protocol.html). \n    This protocol is the native protocol used by the [uWSGI](https://uwsgi-docs.readthedocs.io) server.\n    See 3-th sample for more details.\n\n#### Socket Client\nIncludes **Balancer** and **Pool**, is an importent component of the app. It can connect to any number of servers. It is flexible and easily [configurable](https://github.com/AstRonin/sgi/wiki/Configuration).\nIf server has down then Balancer will not send the requests and it some times will сheck server availability. \n\nBalancer can open new connections as needed on the fly and starts with a small necessary quantity of connections. If some socket will not use some time then this socket will be closed freeing memory.\n\nBalancer has two balancing methods: **blurred** and **priority**. Please look to [Sample 4](https://github.com/AstRonin/sgi/blob/master/README.md#sample-4---part-of-socket-connection) to get an idea of the advantages of each. It will allow to configure Socket Client for different server architectures.\n\n#### Proxy\nApplication be able to create connect through the proxy, now support SOCKS5 protocol, \nand you can send message, for example through the [Tor](https://torproject.org/). \n@see [Configuration](https://github.com/AstRonin/sgi/wiki/Configuration) section.\n\n## Base components\n\n- Server [Cowboy](https://ninenines.eu)\n- Framework [n2o](http://synrc.com/apps/n2o/)\n\n## Requirements\n   \n- Erlang 18.1+\n\n## Documentation\n\nRead documentation in [Wiki](https://github.com/AstRonin/sgi/wiki).\n\n## Upgrade\n\nRead [UPGRADE](https://github.com/AstRonin/sgi/blob/master/UPGRADE.md) before installation new version.\n\n## Try Samples\n\n### Sample 1 - Add a content from other languages inside of your Site.\n\nThis sample shows you how you can add \"Busines Logic\" (big or old) to your site using PHP files.\n\nIt is based on the sample from [n2o](https://github.com/synrc/n2o).\n\n    $ git clone git://github.com/astronin/sgi\n    $ cd sgi/samples\n    $ ./mad deps compile plan\n    $ ./mad repl\n\nRun php as fcgi server:\n\n    $ sudo service php5-fpm start\n\nNow you can try it out: http://localhost:8000\n\n### Sample 2 - Your whole common site after erlang server and WebSocket instead of Ajax.\n\nThis sample shows you how you can run your site (written in other PL) with support of WebSocket. Forget about Ajax and do your page much more faster.\n\nYou have the following advantages compared to Ajax even in common web page:\n- Fast\n- Low overhead, especially over https\n- Easy forwarding a file\n- Saving CPU resources of both a client and a server\n\n##### Setup:\n\n    $ git clone git://github.com/astronin/sgi\n    $ cd sgi/samples\n    \nChange app in rebar.config:\n\n    $ vim samples/apps/rebar.config\n**{sub_dirs, [ \"review\" ]}**. -\u003e **{sub_dirs, [ \"review2\" ]}**.\n\nChange app in sys.config:\n\n**{n2o, [{app,review2}]}**\n\nRun FPM:\n\n    $ sudo service php5-fpm start\n    \nRun Server:\n\n    $ ./mad deps compile plan\n    $ ./mad repl\n\nUrl:  http://localhost:8000/site.php\n\n### Sample 3 - Like Sample 2, but using Python.\n\nThis sample shows you how you can run your site (wrote in Python and support **uwsgi** protocol) with support of WebSocket.\nFor this you need to use server [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/).\n\n##### Setup:\n\n    $ git clone git://github.com/astronin/sgi\n    $ cd sgi/samples\n    \nChange app in rebar.config:\n\n    $ vim samples/apps/rebar.config\n**{sub_dirs, [ \"review\" ]}**. -\u003e **{sub_dirs, [ \"review3\" ]}**.\n\nChange app in sys.config:\n\n```erlang\n{n2o, [{app,review3}]},\n{sgi, [{servers, [\n    [{name, default}, {address, localhost}, {port, 3031}]\n]}]}\n```\n\nRun uWSGI:\n\n    $ uwsgi --socket 127.0.0.1:3031 --wsgi-file \u003cyour path clone\u003esgi/samples/cgi-scripts/python/myapp.py\n\nRun Server:\n\n    $ ./mad deps compile plan\n    $ ./mad repl\n\nUrl:  http://localhost:8000/\n\n### Sample 4 - Part of socket connection\n\nThis sample shows you how you can use TCP Client of this app.\nThanks to the smart balancer Client can connect to any number of servers in different methods: `priority` or `blurred`.\n\n##### Setup:\n\n    $ git clone git://github.com/astronin/sgi\n    $ cd sgi/samples\n    \nChange app in rebar.config:\n\n    $ vim samples/apps/rebar.config\n**{sub_dirs, [ \"review\" ]}**. -\u003e **{sub_dirs, [ \"review4\" ]}**.\n\nChange app in sys.config:\n\n**{n2o, [{app,review4}]}**\n\nChange following settings in `sys.config`. \nSample will start 10 servers with 5 processes.\nClient will connect with 5 sockets on each server.\n\n```erlang\n{servers, [\n    [{name, default}, {address, localhost}, {port, 10000}, {timeout, 60000}, {weight, 10}, {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa1},    {address, localhost}, {port, 10001}, {timeout, 60000}, {weight, 9},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa2},    {address, localhost}, {port, 10002}, {timeout, 60000}, {weight, 8},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa3},    {address, localhost}, {port, 10003}, {timeout, 60000}, {weight, 7},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa4},    {address, localhost}, {port, 10004}, {timeout, 60000}, {weight, 6},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa5},    {address, localhost}, {port, 10005}, {timeout, 60000}, {weight, 5},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa6},    {address, localhost}, {port, 10006}, {timeout, 60000}, {weight, 4},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa7},    {address, localhost}, {port, 10007}, {timeout, 60000}, {weight, 3},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa8},    {address, localhost}, {port, 10008}, {timeout, 60000}, {weight, 2},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}],\n    [{name, aaa9},    {address, localhost}, {port, 10009}, {timeout, 60000}, {weight, 1},  {start_connections, 4}, {max_connections, 5}, {max_fails, 5}, {failed_timeout, 60}]\n]},\n{balancing_method, priority}, %blurred or priority\n```\n    \nRun Server:\n\n    $ ./mad deps compile plan\n    $ ./mad repl\n\nChange in `sys.config` next `{balancing_method, blurred},`\n\n    $ ./mad repl\n\nSample will create the two files: `server_distribution(priority).csv` and `server_distribution(blurred).csv`\nwhich shows difference between two methods of connection balancing to a server.\nOpen files in Excel(or other) and insert `XY(Scater)` graph:\n\n![priority](priority1.png)\nBelow are results with next weights: \n\nServer port | Weight\n--- | ---\n10000 | 1\n10001 | 2\n10002 | 3\n10003 | 4\n10004 | 10\n10005 | 9\n10006 | 8\n10007 | 7\n10008 | 6\n10009 | 5\n![priority](priority2.png)\n![priority](blurred1.png)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastronin%2Fsgi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastronin%2Fsgi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastronin%2Fsgi/lists"}