sgi

其他类别 2025-08-19

sgi插座网关接口

申请写在Erlang上。一般设计原理是:快速,低内存和模块化。

sgi提供了简单而智能的方式,可以通过TCP连接到任何服务器,并在TCP下使用其他协议。它支持两个协议:

  • fastcgi。该协议对于连接到PHP(FPM)是常见的。
  • UW sgi 。该协议是UW sgi服务器使用的本机协议。有关更多详细信息,请参见第三示例。

插座客户端

包括平衡器,是应用程序的重要组成部分。它可以连接到任意数量的服务器。它是灵活的,易于配置。如果服务器的关闭,则Balancer不会发送请求,并且有时会供应服务器的可用性。

平衡器可以随时开放新的连接,并以少量必要的连接开始。如果某些插座不会使用某个时间,则此插座将是封闭的释放内存。

平衡器有两种平衡方法:模糊优先级。请查看样品4,以了解每个4的优势。它将允许为不同的服务器体系结构配置套接字客户端。

代理人

应用程序可以通过代理创建连接,现在支持Socks5协议,您可以通过TOR发送消息。 @See配置部分。

基本组件

  • 服务器牛仔
  • 框架N2O

要求

  • Erlang 18.1+

文档

阅读Wiki中的文档。

升级

在安装新版本之前,请阅读升级。

尝试样本

示例1-从网站内的其他语言中添加内容。

该示例向您展示了如何使用PHP文件向网站添加“ Busines Logic”(大小)。

它基于N2O的样本。

sgi $ cd sgi /samples $ ./mad deps compile plan $ ./mad repl">
 $ git clone git://github.com/astronin/ sgi
$ cd sgi /samples
$ ./mad deps compile plan
$ ./mad repl

以FCGI服务器运行PHP:

 $ sudo service php5-fpm start

现在您可以尝试一下:http:// localhost:8000

示例2-在Erlang Server和Websocket而不是AJAX之后,您的整个公共站点。

该示例向您展示了如何在WebSocket的支持下运行网站(用其他PL编写)。忘记Ajax,然后更快地完成您的页面。

即使在通用网页中,您也具有以下优点:

  • 快速地
  • 低矮的头顶,尤其是在HTTPS上
  • 轻松转发文件
  • 保存客户端和服务器的CPU资源
设置:
sgi $ cd sgi /samples">
 $ git clone git://github.com/astronin/ sgi
$ cd sgi /samples

更改rebar.config中的应用程序:

 $ vim samples/apps/rebar.config

{sub_dirs,[“评论”]} 。 - > {sub_dirs,[“评论2”]}

在sys.config中更改应用程序:

{n2o,[{app,eview2}]}

运行FPM:

 $ sudo service php5-fpm start

运行服务器:

 $ ./mad deps compile plan
$ ./mad repl

URL:http:// localhost:8000/site.php

样品3-喜欢样品2,但使用python。

该示例向您展示了如何在WebSocket的支持下运行网站(在Python和支持UW sgi协议)中运行。为此,您需要使用服务器UW sgi 。

设置:
sgi $ cd sgi /samples">
 $ git clone git://github.com/astronin/ sgi
$ cd sgi /samples

更改rebar.config中的应用程序:

 $ vim samples/apps/rebar.config

{sub_dirs,[“评论”]} 。 - > {sub_dirs,[“评论3”]}

在sys.config中更改应用程序:

sgi, [{servers, [ [{name, default}, {address, localhost}, {port, 3031}] ]}]}">
{ n2o , [{ app , review3 }]},
{ sgi , [{ servers , [
    [{ name , default }, { address , localhost }, { port , 3031 }]
]}]}

运行UW sgi :

sgi -file sgi /samples/cgi-scripts/python/myapp.py">
 $ uw sgi --socket 127.0.0.1:3031 --w sgi -file  sgi /samples/cgi-scripts/python/myapp.py

运行服务器:

 $ ./mad deps compile plan
$ ./mad repl

URL:http:// localhost:8000/

样本4-插座连接的一部分

该示例向您展示了如何使用此应用程序的TCP客户端。多亏了Smart Balancer客户端,可以以不同的方法连接到任意数量的服务器: priorityblurred

设置:
sgi $ cd sgi /samples">
 $ git clone git://github.com/astronin/ sgi
$ cd sgi /samples

更改rebar.config中的应用程序:

 $ vim samples/apps/rebar.config

{sub_dirs,[“评论”]} 。 - > {sub_dirs,[“评论4”]}

在sys.config中更改应用程序:

{n2o,[{app,评论4}]}

更改sys.config中的设置之后。样本将使用5个过程启动10台服务器。客户端将使用每个服务器上的5个插座连接。

{ servers , [
    [{ name , default }, { address , localhost }, { port , 10000 }, { timeout , 60000 }, { weight , 10 }, { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa1 },    { address , localhost }, { port , 10001 }, { timeout , 60000 }, { weight , 9 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa2 },    { address , localhost }, { port , 10002 }, { timeout , 60000 }, { weight , 8 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa3 },    { address , localhost }, { port , 10003 }, { timeout , 60000 }, { weight , 7 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa4 },    { address , localhost }, { port , 10004 }, { timeout , 60000 }, { weight , 6 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa5 },    { address , localhost }, { port , 10005 }, { timeout , 60000 }, { weight , 5 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa6 },    { address , localhost }, { port , 10006 }, { timeout , 60000 }, { weight , 4 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa7 },    { address , localhost }, { port , 10007 }, { timeout , 60000 }, { weight , 3 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa8 },    { address , localhost }, { port , 10008 }, { timeout , 60000 }, { weight , 2 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }],
    [{ name , aaa9 },    { address , localhost }, { port , 10009 }, { timeout , 60000 }, { weight , 1 },  { start_connections , 4 }, { max_connections , 5 }, { max_fails , 5 }, { failed_timeout , 60 }]
]},
{ balancing_method , priority }, % blurred or priority

运行服务器:

 $ ./mad deps compile plan
$ ./mad repl

更改sys.config next {balancing_method, blurred},

 $ ./mad repl

示例将创建两个文件: server_distribution(priority).csvserver_distribution(blurred).csv它显示了两种连接与服务器的连接方法之间的差异。在Excel(或其他)中打开文件,然后插入XY(Scater)图:

以下是下一个重量的结果:

服务器端口 重量
10000 1
10001 2
10002 3
10003 4
10004 10
10005 9
10006 8
10007 7
10008 6
10009 5
下载源码

通过命令行克隆项目:

git clone https://github.com/AstRonin/sgi.git