2017-03-07 26 views
1

我想配置一個nginx作爲負載均衡器在彈性搜索羣集(版本1.3.7)之前。nginx因爲elasticsearch負載均衡性能低

我正在從3個基準服務器到集羣中的3個elasticsearch節點進行測試。 使用nginx作爲LoadBalancer我的性能下降了大約50%。

我能夠在沒有nginx的情況下在300秒內處理28K個請求,但是在300秒內只有13k個請求。 服務器是虛擬機,所以不應該是一個網絡問題,至少,物理問題。 Nginx服務器沒有高cpu負載或其資源有任何限制。

配置是非常簡單的:

user www-data; 
worker_processes auto; 
pid /run/nginx.pid; 
include /etc/nginx/modules-enabled/*.conf; 

worker_rlimit_nofile 4096; 

events { 
     worker_connections 1024; 
} 

和具體的ES:

server { 
    listen  9100; 
    server_name elasticsearch.site.com; 
    location/{ 
     proxy_pass http://elasticsearch; 
     proxy_http_version 1.1; 
     proxy_set_header Connection ""; 
     proxy_set_header Proxy-Connection "Keep-Alive"; 
    } 
    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log error; 
} 

upstream elasticsearch { 
    server elasticsearch1:9200; 
    server elasticsearch2:9200; 
    server elasticsearch3:9200; 
    keepalive 15; 
} 

我想知道是否有任何的方式來理解爲什麼nginx的不能提供每秒請求,或如果有任何方法可以調試這種情況。瞭解超時,保持活動連接或由nginx處理的任何其他資源將會很好。

+0

嘗試haproxy也許?如果你特別想要某種負載平衡。 – Sobrique

+0

如果緩衝是應用程序遇到緩慢的原因,我不會感到驚訝。需要考慮調整的兩個配置選項:[proxy_buffering](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering)和[proxy_request_buffering](http://nginx.org/en/docs/http/ ngx_http_proxy_module.html#proxy_request_buffering)。 – Anatoly

回答

1

您不需要負載平衡器 - ES已經提供了該功能。您只是添加另一個組件,這可能會導致錯誤,並會增加不必要的網絡跳轉。去dns循環賽。

ES會將您的數據分片(默認爲5個分片),它將嘗試在您的實例中均勻分配。根據您的環境調整碎片和副本。

+1

我嘗試使用代理服務器作爲ES客戶端節點,性能稍微好一些,在300秒內達到15K,離理想情況還差得很遠。 添加LB將提供從代碼到平臺基礎結構的隔離。移動羣集會更容易,或者在ES節點中進行更改而不更改代碼。端點將始終相同。 – bvcelari