Create aligned buffers to make faster disk io with less iops
Aligned buffers will allow you to read data from disk much faster than you think you can. For example, if you read 64k blocks from disk to aligned buffers, you may get 50% speed-up.
Install it as usual from npm:
npm install aligned-buffer
var aligned = require"aligned-buffer";
var alignment = alignedalignment;
Getting aligned buffer:
var buf = alignedbuffer/* alignment, don't change*/ alignedalignment /* size */ 1024 * 64;
You will need at least node-0.8.9 to support O_DIRECT flag.
If you want to use it with older node, you need to find out O_DIRECT
value by yourself (
fgrep O_DIRECT /usr/include for linux).
var fs = require"fs"aligned = require"aligned-buffer"constants = processbinding"constants"fd = fsopenSync"/my_big_file" constantsO_RDONLY | constantsO_DIRECTsize = 64 * 1024 // 64k blocksbuf = alignedbufferalignedalignment sizeoffset = 0;// offset should be aligned to buf.length,// so allowed values are: 0, 64k, 128k, 172k// if offset is not aligned you will receive no boostfsreadfd buf 0 buflength offsetif errorconsole.logerror;return;console.log"successful read!";;