spooledtempfile

package
v0.8.63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2025 License: CC0-1.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxRAMUsageFraction = 0.50

DefaultMaxRAMUsageFraction is the default fraction of system RAM above which we'll force spooling to disk. For example, 0.5 = 50%.

View Source
const MaxInMemorySize = 1024 * 1024

MaxInMemorySize is the max number of bytes (currently 1MB) to hold in memory before starting to write to disk

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	ReaderAt
	io.Closer
	FileName() string
	Len() int
}

ReadSeekCloser is an io.Reader + ReaderAt + io.Seeker + io.Closer + Stat

type ReadWriteSeekCloser

type ReadWriteSeekCloser interface {
	ReadSeekCloser
	io.Writer
}

ReadWriteSeekCloser is an io.Writer + io.Reader + io.Seeker + io.Closer.

func NewSpooledTempFile

func NewSpooledTempFile(
	filePrefix string,
	tempDir string,
	threshold int,
	fullOnDisk bool,
	maxRAMUsageFraction float64,
) ReadWriteSeekCloser

NewSpooledTempFile returns an ReadWriteSeekCloser, with some important constraints:

  • You can Write into it, but whenever you call Read or Seek on it, subsequent Write calls will panic.
  • If threshold is -1, then the default MaxInMemorySize is used.
  • If maxRAMUsageFraction <= 0, we default to DefaultMaxRAMUsageFraction. E.g. 0.5 = 50%.

If the system memory usage is above maxRAMUsageFraction, we skip writing to memory and spool directly on disk to avoid OOM scenarios in high concurrency.

From our tests, we've seen that a bytes.Buffer minimum allocated size is 64 bytes, any threshold below that will cause the first write to be spooled on disk.

type ReaderAt

type ReaderAt interface {
	ReadAt(p []byte, off int64) (n int, err error)
}

ReaderAt is the interface for ReadAt - read at position, without moving pointer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL