我正在使用Websockets将网站上的通信发送到我使用nodejs KOA构建的后端服务器。我正在使用websockets库1.4.x,它正在AWS elasticbeanstalk中托管。我遇到的问题是每秒有太多的轮询请求,而且AWS Elasticbeanstalk已将我的群集归类为Degraded。网站使用率非常低,我实际上并没有向网站推送任何内容。我使用websockets发回报告数据。我可能应该改为使用POST或AJAX,这将解决我的问题。但是,我想知道是否有人可以帮助解释为什么我看到这么多的民意调查请求?对于加载了站点的每个客户端,它每秒发送一个轮询请求:
2016-05-24T03:33:37.025471Z 0.000037 0.001259 0.000019 400 400 3 41 "POST http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqo-g&sid=2p4uqRwRpgAGe9MYGEFw HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.058664Z 0.000046 0.000801 0.000021 400 400 0 41 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=websocket&sid=VGMrEcNWfe3V52xIBrsr HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.068053Z 0.000026 0.001814 0.000017 400 400 3 41 "POST http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqq6w&sid=VGMrEcNWfe3V52xIBrsr HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.114333Z 0.000027 0.001408 0.000028 200 200 0 101 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqptG HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.204186Z 0.000049 0.000999 0.000018 400 400 0 41 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqpwy&sid=70GDwJbapBpe7xr0Brss HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.222283Z 0.000027 0.002033 0.000019 200 200 0 101 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqpdt HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.284256Z 0.00004 0.001299 0.00002 400 400 0 34 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=websocket&sid=70GDwJbapBpe7xr0Brss HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.304609Z 0.000025 0.000778 0.000016 400 400 3 41 "POST http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqpyM&sid=70GDwJbapBpe7xr0Brss HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.334223Z 0.00003 0.001927 0.000021 200 200 0 5 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqpfN&sid=t4oUghKESf3iQDNIGEFx HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.412382Z 0.000025 0.001156 0.000027 400 400 0 41 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=websocket&sid=t4oUghKESf3iQDNIGEFx HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.460320Z 0.000025 0.001016 0.000029 400 400 0 41 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqph5&sid=t4oUghKESf3iQDNIGEFx HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.562313Z 0.000061 0.002397 0.000026 200 200 3 2 "POST http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqpj7&sid=t4oUghKESf3iQDNIGEFx HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.878069Z 0.000057 0.001508 0.000019 200 200 0 101 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqqIm HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
2016-05-24T03:33:37.978133Z 0.000043 0.001061 0.000033 400 400 0 41 "GET http://xxx.elb.amazonaws.com:80/socket.io/?EIO=3&transport=polling&t=LJWqqKp&sid=az8li1OVGN8CuKc7Brst HTTP/1.1" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" - -
服务器端代码是:
var http = require('http');
var koa = require('koa');
var app = koa();
app.use(router.routes())
.use(router.allowedMethods());
router.get('/', getHomepage );
router.get('/:storeid', getHomepage );
app.context.render = render({
root: path.join(__dirname, 'views'),
autoescape: true,
cache: 'memory', // disable, set to false
ext: 'html',
// locals: locals,
// filters: filters,
// tags: tags,
// extensions: extensions
});
app.use(staticFolder('./public'));
var server = http.createServer(app.callback());
var io = require('socket.io')(server);
var storeId=0;
io.on('connection', function (socket)
{
socket.on('submit', function(data)
{
// Do something
}
));
在客户端我有:
<script type="text/javascript" src="socket.io/socket.io.js"></script>
<script type="text/javascript"> var socket = new io('http://xxx.elb.amazonaws.com'); </script>
答案 0 :(得分:0)
想出来。亚马逊ELB不支持WebSockets !!!