Documentation ¶
Overview ¶
Package hddreader wraps an os.File object with a algorithm which tries to optimise parallel reading of multiple files from a hdd. It does this by limiting number of open files and reading files in order of disk offsets. Main components: File: file object, semi-interchangeable with os.File. Implements: Reader, Closer, WriterTo Disk: disk object, schedules file reads bufferpool: pool of reusable same-sized []byte buffers
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Disk ¶
type Disk struct {
// contains filtered or unexported fields
}
A Disk schedules read operations for files. It shoulds be created using NewDisk. A call to Disk.Start() is required before the disk will allow associated files to start reading data.
Example usage:
d := hddreader.NewDisk(1, 0, 0, 0, 100, 64) for _, p := range(paths) { wg.Add(1) go read_stuff_from(p, &wg) // calls hddreader.OpenFile() and file.Read() but will block until d.Start() called } d.Start() // enables reading and will unblock pending Read() calls in disk offset order wg.Wait() d.Close()
func NewDisk ¶
NewDisk creates a new disk object to schedule read operations in order of increasing physical offset on the disk.
Up to maxread files will be read concurrently. An additional up to maxwindow files may be opened for reading if they are within (-behind,+ahead) bytes of the current head position. An additional up to maxopen files may be open for the sole purpose of reading disk offset.
If bufkB > 0 then an internal buffer pool is created to buffer WriteTo() calls. Note that while read order is preserved, buffering may change the order in which WriteTo(w) calls complete, depending on speed at which buffers are writted to w.
type File ¶
type File struct { Offset uint64 // file location relative to start of disk // contains filtered or unexported fields }
a File struct wraps an os.File stuct with the necessary field and methods for hdd-optimised reads.
func Open ¶
Open creates a new File object associated with a Disk, and register the file's physical position on the disk. It may block until the disk's total open file count falls below the disk's open file limit.