Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich method of caching is the fastest/lightest for Node/Mongo/NginX?
    primarykey
    data
    text
    <p>I've been tasked to work on a project for a client that has a site which he is estimating will receive 1-2M hits per day. He has an existing database of 58M users that need to get seeded on a per-registration basis for the new brand. Most of the site's content is served up from external API supplied data with most of the data stored on our Mongo setup being profile information and saved API parameters. </p> <p>NginX will be on port 80 and load balancing to a Node cluster on ports 8000 - 8010. </p> <p>My question is what to do about caching. I come from a LAMP background so I'm used to either writing static HTML files with PHP and serving those up to minimize MySQL load or using Memcached for sites that required a higher level of caching. This setup is a bit foreign to me. </p> <p>Which is the most ideal as far as <strong>minimal response time and CPU load</strong>?</p> <h2>1: Page-level caching with NginX</h2> <p>Reference: <a href="http://andytson.com/blog/2010/04/page-level-caching-with-nginx/">http://andytson.com/blog/2010/04/page-level-caching-with-nginx/</a></p> <pre><code>server { listen 80; servername mysite.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; location / { proxy_pass http://localhost:8080/; proxy_cache anonymous; } # don't cache admin folder, send all requests through the proxy location /admin { proxy_pass http://localhost:8080/; } # handle static files directly. Set their expiry time to max, so they'll # always use the browser cache after first request location ~* (css|js|png|jpe?g|gif|ico)$ { root /var/www/${host}/http; expires max; } } </code></pre> <p><br /></p> <h2>2: Redis as a cache bucket</h2> <p>The <code>hash()</code> function is the <code>numbers()</code> function on this page: <a href="http://jsperf.com/hashing-strings">http://jsperf.com/hashing-strings</a></p> <pre><code>function hash(str) { var res = 0, len = str.length; for (var i = 0; i &lt; len; i++) { res = res * 31 + str.charCodeAt(i); } return res; } var apiUrl = 'https://www.myexternalapi.com/rest/someparam/someotherparam/?auth=3dfssd6s98d7f09s8df98sdef'; var key = hash(apiUrl).toString(); // 1.8006908172911553e+136 myRedisClient.set(key,theJSONresponse, function(err) {...}); </code></pre> <p><br /></p> <h2>3: Node write JSON files</h2> <p>The <code>hash()</code> function is the <code>numbers()</code> function on this page: <a href="http://jsperf.com/hashing-strings">http://jsperf.com/hashing-strings</a></p> <pre><code>function hash(str) { var res = 0, len = str.length; for (var i = 0; i &lt; len; i++) { res = res * 31 + str.charCodeAt(i); } return res; } var fs = require('fs'); var apiUrl = 'https://www.myexternalapi.com/rest/someparam/someotherparam/?auth=3dfssd6s98d7f09s8df98sdef'; var key = hash(apiUrl).toString(); // 1.8006908172911553e+136 fs.writeFile('/var/www/_cache/' + key + '.json', theJSONresponse, function(err) {...}); </code></pre> <p><br /></p> <h2>4: Varnish in front</h2> <p>I did some research and benchmarks like the ones shown on this site are leaning me away from this solution, but I'm still open to consider it if it makes the most sense: <a href="http://todsul.com/nginx-varnish">http://todsul.com/nginx-varnish</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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