Faye-rails, ngnix, passenger slow response from faye

I want to create a simple chat. I am not a server administration guru. So I have a question about ngnix and faye.

I am using ngnix + passenger for my server. I have a tiny bit on digitalocean and want to deploy my application on this. Therefore, for deployment, I use the official textbook for passengers https://www.phusionpassenger.com/library/install/nginx/install/oss/trusty/

For model callbacks, I use faye-rails gem. As faye-rails say, if I use a passenger, I need to use this configuration

config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25, server: 'passenger', engine: {type: Faye::Redis, host: 'localhost'} do map '/announce/**' => SomeController end 

In my development, localhost: 3000 chat works fine. But when I deploy it, it works very slowly (the answer comes in the interval from 5 to 60 seconds). I do not know how to fix this.

In my /etc/ngnix/sites-enabled/myapp.conf I use this configuration:

 server { listen 80; server_name server_ip; # Tell Nginx and Passenger where your app 'public' directory is root /project_path_to_public; # Turn on Passenger passenger_enabled on; passenger_ruby /ruby_wrapper_path; } 

I need to update my /etc/ngnix/sites-enabled/myapp.conf and how? Or what do I need to do?

+5
source share
1 answer

I am currently using Faye and Redis in the application I am developing. This is not a direct solution to the current installation of the issue, but an alternative method that I implemented. Below is my nginx configuration, and then I run Faye through rackup on the screen on the server.

/etc/nginx/sites-enabled/application.conf:

 server { listen 80; listen [::]:80; server_name beta.application.org; # Tell Nginx and Passenger where your app 'public' directory is root /var/www/application/current/public; # Turn on Passeger passenger_enabled on; passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby; rails_env production; location ~* ^/assets/ { # Per RFC2616 - 1 year maximum expiry # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html expires 1y; add_header Cache-Control public; add_header Last-Modified ""; add_header ETag ""; break; } } map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream websocket { server 127.0.0.1:9292; } server { listen 8020; location / { proxy_pass http://127.0.0.1:9292/push; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } } 

This link should give a little idea of ​​how it works. https://chrislea.com/2013/02/23/proxying-websockets-with-nginx/

You can also refer to Feee github for some tips on setting it up with Passenger.

Also, if you followed Digital Ocean's tutorials for initial server setup and eventually turned on the firewall, make sure that you allow the ports that Faye / websockets runs on. (See here when setting up a basic firewall: Additional Recommended Steps for New Ubuntu 14.04 Servers

My alternative method involves running Faye on a separate screen on the server. A few commands that you will need to control the screens on the ubuntu server:

 screen -S <pick screen name> (new screen) screen -ls (lists screens) screen -r <screen number> (attach screen) to quit from a screen, ctrl + a THEN "d" (detach screen) 

Once you have a new screen, start the Faye server on this screen using rackup: rackup faye.ru -s thin -E production

As a note, with this option, every time you restart your Digital Ocean server (i.e. when creating a screenshot as a backup), you will need to create a new screen and start the faye server again; however using something like Daemon would be a better implementation to get around this (I just haven't implemented it yet ...). Go to Github and find FooBarWidget / daemon_controller.

Let me know if you have any other questions and I will try to help!

0
source

Source: https://habr.com/ru/post/1240688/


All Articles