{"action":"created","issue":{"url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/4124","labels_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/4124/labels{/name}","comments_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/4124/comments","events_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/4124/events","html_url":"https://github.com/qbittorrent/qBittorrent/issues/4124","id":117026518,"number":4124,"title":"qBittorrent performs horribly wrong disk I/O","user":{"login":"AyrA","id":1301960,"avatar_url":"https://avatars.githubusercontent.com/u/1301960?v=3","gravatar_id":"","url":"https://api.github.com/users/AyrA","html_url":"https://github.com/AyrA","followers_url":"https://api.github.com/users/AyrA/followers","following_url":"https://api.github.com/users/AyrA/following{/other_user}","gists_url":"https://api.github.com/users/AyrA/gists{/gist_id}","starred_url":"https://api.github.com/users/AyrA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AyrA/subscriptions","organizations_url":"https://api.github.com/users/AyrA/orgs","repos_url":"https://api.github.com/users/AyrA/repos","events_url":"https://api.github.com/users/AyrA/events{/privacy}","received_events_url":"https://api.github.com/users/AyrA/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-15T23:26:35Z","updated_at":"2015-11-16T07:17:00Z","closed_at":"2015-11-16T00:12:47Z","body":"I have set qBittorrent to pre-allocate files to prevent fragmentation. It seems that this is not implemented correctly, as it takes minutes instead of milliseconds. This seems to be due to two mistakes in qBittorrent:\r\n\r\n- When pre-allocating, qBittorrent seems to allocate the file by writing to it, instead of creating a sparse file.\r\n- When allocating, qBittorrent also reads from the file, which **at least** doubles the time you would need to just write to the file.\r\n\r\nWriting zeros to a file is old-school and should no longer be done, instead, mark a file as sparse and just set its length. This is not only faster, but also easier, because it requires no loop.\r\n\r\n[Example code](http://pastebin.com/RwCG4Ftu). This works universally on all operating systems regardless of the filesystem.\r\n\r\nif you fear of a file not being zeroed, don't worry:\r\n\r\n> Windows will consistently return zeroes when the client reads the file. This is covered in the algorithms described in the MS-FSA document (Sections 3.1.1.5 Per Stream, and 3.1.5.2 Application Requests a Read). **NTFS guarantees to never expose the previous contents of a sector that is allocated to a file.**\r\n\r\n**Result:** I have an SSD as my primary disk, but neither reads nor writes are close to the maximum:\r\n\r\n![Pic](http://i.imgur.com/SQl5m9m.png)\r\n\r\n[Microsoft article about sparse files](http://blogs.msdn.com/b/openspecification/archive/2010/11/05/notes-on-sparse-files-and-file-sharing.aspx)\r\n\r\n**Suggested solution**: Let the system handle sparse file creation and do not read from the file until something useful has been written to it. Even if the content would not be  zeroed correctly, the piece map would show these parts as \"unavailable\" as they have never been downloaded. This will at least half the time needed to create the files."},"comment":{"url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/comments/156944163","html_url":"https://github.com/qbittorrent/qBittorrent/issues/4124#issuecomment-156944163","issue_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/4124","id":156944163,"user":{"login":"AyrA","id":1301960,"avatar_url":"https://avatars.githubusercontent.com/u/1301960?v=3","gravatar_id":"","url":"https://api.github.com/users/AyrA","html_url":"https://github.com/AyrA","followers_url":"https://api.github.com/users/AyrA/followers","following_url":"https://api.github.com/users/AyrA/following{/other_user}","gists_url":"https://api.github.com/users/AyrA/gists{/gist_id}","starred_url":"https://api.github.com/users/AyrA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AyrA/subscriptions","organizations_url":"https://api.github.com/users/AyrA/orgs","repos_url":"https://api.github.com/users/AyrA/repos","events_url":"https://api.github.com/users/AyrA/events{/privacy}","received_events_url":"https://api.github.com/users/AyrA/received_events","type":"User","site_admin":false},"created_at":"2015-11-16T07:17:00Z","updated_at":"2015-11-16T07:17:00Z","body":"But why are you reading from the file at the same time?"}}