ronomon / direct-io Goto Github PK
View Code? Open in Web Editor NEWDirect IO helpers for block devices and regular files on FreeBSD, Linux, macOS and Windows.
License: MIT License
Direct IO helpers for block devices and regular files on FreeBSD, Linux, macOS and Windows.
License: MIT License
Thanks again for updating the Windows library. We are using Electron to build a Windows & OS X app, and since Electron ships with Node 7.9.0 built in the module won't compile (error shown below).
I realize O_DIRECT will only work on Node 9.2.0+, however it would be great to add least be able to install the library. Right now we have to use some crazy try / catch tricks to avoid errors when we require the library since we need it for OS X and even with that have some issues with newer versions of npm.
PS C:\Users\GoChip\gochip\GoChipPlayer-Electron\app> npm install
ChipPlayer-Electron\app\node_modules\.staging\@ronomon\queue-4d47975e\nod
> @ronomon/[email protected] install C:\Users\GoChip\gochip\GoChipPlayer-Electron\app\node_modules\@ronomon\direct-io
> node-gyp rebuild
C:\Users\GoChip\gochip\GoChipPlayer-Electron\app\node_modules\@ronomon\direct-io>if not defined npm_config_node_gyp (node "C:\Users\GoChip\scoop\apps\nodejs\7.10.1\node_modules\npm\bin\node-gyp-
bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )
Warning: Missing input files:
C:\Users\GoChip\gochip\GoChipPlayer-Electron\app\node_modules\@ronomon\direct-io\build\Release\binding.node
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
binding.cc
win_delay_load_hook.cc
..\binding.cc(145): error C3861: 'uv_get_osfhandle': identifier not found [C:\Users\GoChip\gochip\GoChipPlayer-Electron\app\node_modules\@ronomon\direct-io\build\binding.vcxproj]
..\binding.cc(374): error C3861: 'uv_get_osfhandle': identifier not found [C:\Users\GoChip\gochip\GoChipPlayer-Electron\app\node_modules\@ronomon\direct-io\build\binding.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\GoChip\scoop\apps\nodejs\7.10.1\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:194:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Users\\GoChip\\scoop\\apps\\nodejs\\current\\node.exe" "C:\\Users\\GoChip\\scoop\\apps\\nodejs\\7.10.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuil
d"
gyp ERR! cwd C:\Users\GoChip\gochip\GoChipPlayer-Electron\app\node_modules\@ronomon\direct-io
gyp ERR! node -v v7.10.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok
npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Users\\GoChip\\scoop\\apps\\nodejs\\current\\node.exe" "C:\\Users\\GoChip\\scoop\\apps\\nodejs\\current\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v7.10.1
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ronomon/[email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
Trying to use getBlockDevice()
on a loop device on Linux.
var blockdev = dio.getBlockDevice(fd, function(e) {
console.error('Couldn\'t get block device: ' + JSON.stringify(e.message))
})
It gives me Couldn't get block device: "SG_GET_VERSION_NUM failed"
Is it expected?
Thanks for creating this library, it's perfect for what we need. I created a script to test doing direct IO on OS X. I'm reading a 240 MB file off an SD card, so the disk cache should be effectively non-existent.
Flag set to 1: 13.6s
Flag set to 1: 13.6s
Flag set to 0: 13.6s
Flag set to 0: 0.3s
Flag set to 1: 0.3s
Flag set to 1: 0.3s
It appears that as long as you do non-cached reads, you get direct IO, however the moment it's loaded in the cache, the F_NOCACHE
flag gets ignored.
SD cards tend to be pretty unreliable, so we want to write files to the card and then immediately read them back to ensure the contents were written without any errors. I'm concerned that the file will still be in the filesystem cache even with the F_NOCACHE
flag set since we just wrote it.
Also, it looks like you completed the work to support direct IO on Windows via libuv. Is that something that is ready to be implemented now? We'd love to turn this on for Windows as well.
const directIO = require('@ronomon/direct-io');
const path = '/path/to/file';
const cache = 1;
let fd, info;
info = fs.statSync(path);
const alignedSize = Math.ceil(info.size / 4096) * 4096;
const alignedBuffer = directIO.getAlignedBuffer(alignedSize, 4096);
console.log('Size', info.size, alignedSize);
fd = fs.openSync(path, 'r');
console.log('Set flag to', cache);
directIO.setF_NOCACHE(fd, cache, () => {
fs.read(fd, alignedBuffer, 0, alignedSize, (err, bytesRead, buffer) => {
console.log('Read', bytesRead);
fs.closeSync(fd);
});
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.