Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: I do see in the original question that there was no problems running under Linux, however, I was facing difficulties on Linux as well, under "high load" scenarioes (i.e +50 concurrent requests) so this might apply to OS X as well...</p> <p>I dug a little deeper into this problem and I found a solution to my setup - I'm no longer recieving 502 Bad Gateway errors when load testing my simple hello world application. I tested everyting on Ubuntu 13.10 with a fresh compile of Mono 3.2.3 installed in /opt/mono.</p> <p>When you start the mono-fastcgi-4 server with "/verbose=True /printlog=True" you will notice the following output:</p> <pre><code>Root directory: /some/path/you/defined Parsed unix:/tmp/nginx-1.sockets as URI unix:/tmp/nginx-1.sockets Listening on file /tmp/nginx-1.sockets with default permissions Max connections: 1024 Max requests: 1024 </code></pre> <p>The important lines are "max connections" and "max requests". These basically tells how many active TCP connections and requests the mono-fastcgi server will be able to handle - in this case 1024.</p> <p>My NGINX configuration read:</p> <pre><code>worker_processes 4; events { worker_connections 1024; } </code></pre> <p>So I have 4 workers, <em>which each can have 1024 connections</em>. Thus NGINX happily accepts 4096 concurrent connections, which are then sent to mono-fastcgi (who only wishes to handle 1024 conns). Therefore, mono-fastcgi is "protecting it self" and stops serving requests. There are two solutions to this:</p> <ol> <li>Lower the amount of requests that NGINX can accept</li> <li>Increase your fastcgi upstream pool</li> </ol> <p>1 is trivially solved by changing NGINX configuration to read something like:</p> <pre><code>worker_processes 4; # &lt;-- or 1 here events { worker_connections 256; # &lt;--- if 1 above, then 1024 here } </code></pre> <p>However, this could verly likely mean that you're not able to max the resources on your machine. </p> <p>The solution to 2. is a bit more tricky. First, mono-fastcgi must be started multiple times. For this I created the following script (inside the website that should be started):</p> <pre><code>function startFastcgi { /opt/mono/bin/fastcgi-mono-server4 /loglevels=debug /printlog=true /multiplex=false /applications=/:`pwd` /socket=$1 &amp; } startFastcgi 'unix:/tmp/nginx-0.sockets' startFastcgi 'unix:/tmp/nginx-1.sockets' startFastcgi 'unix:/tmp/nginx-2.sockets' startFastcgi 'unix:/tmp/nginx-3.sockets' chmod 777 /tmp/nginx-* </code></pre> <p>Which starts 4 mono-fastcgi workers that can each accept 1024 connections. Then NGINX should be configured something like this:</p> <pre><code>upstream servercom { server unix:/tmp/nginx-0.sockets; server unix:/tmp/nginx-1.sockets; server unix:/tmp/nginx-2.sockets; server unix:/tmp/nginx-3.sockets; } server { listen 80; location / { fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_pass servercom; include fastcgi_params; } } </code></pre> <p>This configures NGINX with a pool of 4 "upstream workers" which it will use in a <a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html" rel="noreferrer" title="round-robin fashion">round-robin fashion</a>. Now, when I'm hammering my server with <a href="https://github.com/tarekziade/boom" rel="noreferrer" title="Boom">Boom</a> in concurrency 200 for 1 minute, it's all good (aka no 502 at all).</p> <p>I hope you can somehow apply this to your code and make stuff work :)</p> <p>P.S:</p> <p>You can download my Hello World ServiceStack code that I used to test <a href="https://github.com/nover/service-stack-fastcgi-heroku" rel="noreferrer" title="here">here</a>.</p> <p>And you can download my full NGINX.config <a href="http://ge.tt/5xxs8Ry/v/0%20here" rel="noreferrer">here</a>.</p> <p>There are some paths that needs to be adjusted though, but it should serve as a good base.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload