title: Fastest Way To Calculate Directory Sizes
body: <p>what is the best and <strong>fastest</strong> way to calculate directory sizes? For example we will have the following structure:</p>
  
  <pre><code>/users
        /a
        /b
        /c
        /...
  </code></pre>
  
  <p>We need the output to be per user directory:</p>
  
  <pre><code>a = 1224KB
  b = 3533KB
  c = 3324KB
  ...
  </code></pre>
  
  <p>We plan on having tens maybe even hundred of thousands of directories under /users. The following shell command works:</p>
  
  <pre><code>du -cms /users/a | grep total | awk '{print $1}'
  </code></pre>
  
  <p>But, we will have to call it N number of times. The entire point, is that the output; each users directory size will be stored in our database. Also, we would love to have it update as frequently as possible, but without blocking all the resources on the server. Is it even possible to have it calculate users directory size every minute? How about every 5 minutes?</p>
  
  <p>Now that I am thinking about it some more, would it make sense to use node.js? That way, we can calculate directory sizes, and even insert into the database all in one transaction. We could do that as well in PHP and Python, but not sure it is as fast.</p>
  
  <p>Thanks. </p>