小编use*_*369的帖子

优化postgres搜索查询的问题

我遇到以下PostgreSQL查询的问题,运行需要10秒以上是否有任何方法可以将此查询加速到合理的速度,我只是在非常大的数据库中寻找与视频相关的最相关的搜索词.

  SELECT count(*), videoid 
  FROM term_search 
  where word = 'tester' 
     OR word = 'question' 
     OR word = 'one' 
  group by videoid 
  order by count(*) desc 
  limit 1800;
Run Code Online (Sandbox Code Playgroud)

当使用analyze运行查询时,生成的查询计划如下(http://explain.depesz.com/s/yDJ):

  Limit  (cost=389625.50..389630.00 rows=1800 width=4) (actual time=11766.693..11770.001 rows=1800 loops=1)
     Output: (count(*)), videoid
     ->  Sort  (cost=389625.50..389692.68 rows=26873 width=4) (actual time=11766.689..11767.818 rows=1800 loops=1)
           Output: (count(*)), videoid
           Sort Key: (count(*))
           Sort Method: top-N heapsort  Memory: 181kB
           ->  HashAggregate  (cost=387769.41..388038.14 rows=26873 width=4) (actual time=9215.653..10641.993 rows=1632578 loops=1)
                 Output: count(*), videoid
                 ->  Bitmap Heap Scan on public.term_search …
Run Code Online (Sandbox Code Playgroud)

sql postgresql query-optimization top-n

5
推荐指数
1
解决办法
227
查看次数

带有nginx负载均衡器问题的Socket.IO集群

我正在运行NGINX作为Socket.IO服务器的反向代理,该服务器负载平衡多个集群进程的请求.每个集群进程都被告知要侦听不同的端口.

nginx服务器配置为基于IP哈希加载平衡,但我收到消息:

ws://{domain}/socket.io/?EIO=3&transport=websocket&sid=KaU3C8caGVK4gU1LAAAB failed: WebSocket is closed before the connection is established.

我的nginx配置有:

http {
    {+ default configs}

    upstream io_nodes {
        ip_hash;
        server 127.0.0.1:3000;
        server 127.0.0.1:3001;
        server 127.0.0.1:3002;
        server 127.0.0.1:3003;
    }

}
Run Code Online (Sandbox Code Playgroud)

默认vhost:

server {
#listen   80; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www/static/web;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name {domain};

location / {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; …
Run Code Online (Sandbox Code Playgroud)

nginx node.js socket.io

5
推荐指数
1
解决办法
888
查看次数

标签 统计

nginx ×1

node.js ×1

postgresql ×1

query-optimization ×1

socket.io ×1

sql ×1

top-n ×1