Git Product home page Git Product logo

iox's Introduction

iox: I/O tools for Go programs

Package iox contains two Go objects of note: Filer and BufferFile.

https://godoc.org/crawshaw.io/iox

Filer

Managing file resources in highly-concurrent programs gets tricky. A process easily, even typically, has more in-flight goroutines than allowed file descriptors from the operating system. This requires programmers limit the number of open descriptors with some kind of throttle object.

An iox.Filer wraps the functions used to open file descriptors and makes sure it never opens more than some maximum (typically derived from the processes rlimit).

It wraps *os.File pointers in a new object which returns the file descriptor allotment to the Filer pool when Close is called.

BufferFile

A BufferFile is a file-like object that stores its first N bytes in memory, and the rest in a temporary file on disk.

It is designed for loads where the typical case fits in some small amount of memory, but the worst case requires more space than can be provisioned in RAM. (This usually means a server is handling tens to hundreds of thousands of simultaneous requests.)

BufferFile does not create its temporary backing file until its contents exceed the memory buffer, so the typical case does not require any file descriptors. Programs can begin (and usually complete) processing a request without ever blocking on file descriptors, meaning a server never runs into file descriptors as a bottleneck when processing a typical workload.

Installation

Install with:

go get crawshaw.io/iox

There are no version numbers yet, this package needs some time to bake.

iox's People

Contributors

crawshaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

iox's Issues

Add BufferFile.Size() int64

I would love to use BufferFile to stage downloads I don't know the size of before copying them into SQLite blobs, but currently I still have to keep track of their size manually (while with os.File I'd use Stat).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.