node.jsapachewebsocketserver-load

High Load on server due to websocket and Apache


We have 2 servers (Ubuntu 14.04 - 4vCPUs and 12 GB RAM), running a codeigniter application with Apache 2.4.7. These servers are load balanced as well. We have an average of 300 users accessing the site at a time and also the website has refresh functionality in many areas. So we introduced websockets to reduce the load. But even after introducing that, we are facing high load. Node is running on one of these server. After enabling mod_status I can see new connections are not getting opened for apache.

Vhost

<VirtualHost *:443>
    ServerName  domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html/domain
    SSLEngine on
    SSLProxyEngine On
    SSLCertificateFile /etc/apache2/ssl/domain-ssl/a.crt
    SSLCertificateKeyFile /etc/apache2/ssl/domain-ssl/domain.key
    SSLCertificateChainFile /etc/apache2/ssl/domain-ssl/gd_bundle.crt
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

   RewriteEngine On
   RewriteCond %{REQUEST_URI}  ^/node/socket.io [NC]
   RewriteCond %{QUERY_STRING} transport=websocket [NC]
   RewriteRule "^/node/socket.io"  "ws://IPADDRESS:8080/socket.io/" [P,L]
   ProxyPreserveHost On
   ProxyRequests off
</VirtualHost>
<Location /node/>
       RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
       RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
       ProxyPass http://IPADDRESS:8080/ connectiontimeout=3 timeout=3 retry=0
       ProxyPassReverse http://IPADDRESS:8080/
</Location>

Please let me know the details you need to investigate on this. Thanks


Solution

  • I installed a seperate server for node and redis which has reduced the load.