Created
June 28, 2012 12:01
-
-
Save karmi/0a2b0e0df83813a4045f to your computer and use it in GitHub Desktop.
Nginx as a keep-alive proxy for elasticsearch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install: | |
# | |
# brew update | |
# brew install elasticsearch | |
# brew install nginx | |
elasticsearch -D es.http.port='9200' -D es.cluster.name='elasticsearch_proxy_test' -D es.node.name='test-nginx-1' | |
#elasticsearch -D es.http.port='9201' -D es.cluster.name='elasticsearch_proxy_test' -D es.node.name='test-nginx-2' | |
echo ' | |
events { | |
worker_connections 1024; | |
} | |
http { | |
upstream elasticsearch { | |
server 127.0.0.1:9200; | |
#server 127.0.0.1:9201; | |
keepalive 15; | |
} | |
server { | |
listen 8080; | |
server_name elasticsearch_proxy; | |
error_log elasticsearch_proxy-errors.log; | |
access_log elasticsearch_proxy.log; | |
location / { | |
proxy_pass http://elasticsearch; | |
proxy_http_version 1.1; | |
proxy_set_header Connection "Keep-Alive"; | |
proxy_set_header Proxy-Connection "Keep-Alive"; | |
} | |
} | |
} | |
' > ./nginx_elasticsearch_proxy.conf | |
nginx -p '/Users/karmi/Playground/ElasticSearch/Varia/' -c 'nginx_elasticsearch_proxy.conf' | |
# Connection to ES directly | |
# | |
curl 'localhost:9200/_cluster/nodes/stats?pretty&clear&http' | |
# | |
# => Check `http.total_opened`, increasing by 1 | |
# Connection to nginx | |
# | |
curl 'localhost:8080/_cluster/nodes/stats?pretty&clear&http' | |
# | |
# Check `http.total_opened`, should stay put | |
# Multiple sequential connections | |
# | |
for i in {1..100}; do curl 'localhost:8080/_cluster/nodes/stats?pretty&clear&http'; done | |
# Multiple simultaneous connections | |
# | |
for i in {1..100}; do bash -c "(curl 'localhost:8080/_cluster/nodes/stats?pretty&clear&http') &"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment