Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bobrik/node-aligned-buffer
Create aligned buffers to make faster disk io with less iops
https://github.com/bobrik/node-aligned-buffer
Last synced: 10 days ago
JSON representation
Create aligned buffers to make faster disk io with less iops
- Host: GitHub
- URL: https://github.com/bobrik/node-aligned-buffer
- Owner: bobrik
- Created: 2012-08-27T19:14:54.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-10-16T04:27:00.000Z (about 12 years ago)
- Last Synced: 2024-09-18T08:33:55.586Z (about 2 months ago)
- Language: C++
- Homepage: http://bobrik.name
- Size: 105 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Aligned buffers for node.js
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.## Installation
Install it as usual from npm:
```
npm install aligned-buffer
```## API
Require module:
```javascript
var aligned = require("aligned-buffer");
```Getting alignment:
```javascript
var alignment = aligned.alignment();
```Getting aligned buffer:
```javascript
var buf = aligned.buffer(/* alignment, don't change*/ aligned.alignment(), /* size */ 1024 * 64);
```## Usage
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).```javascript
var fs = require("fs"),
aligned = require("aligned-buffer"),
constants = process.binding("constants"),
fd = fs.openSync("/my_big_file", constants.O_RDONLY | constants.O_DIRECT),
size = 64 * 1024, // 64k blocks
buf = aligned.buffer(aligned.alignment(), size),
offset = 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 boostfs.read(fd, buf, 0, buf.length, offset, function(error) {
if (error) {
console.log(error);
return;
}console.log("successful read!");
});
```## Authors
* [Ian Babrou](https://github.com/bobrik)