read_file

package module
v0.0.0-...-7437abc Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

xk6-read-file

This is a k6 extension using the xk6 system.

It is lightweight, fast and concurrent file reader. Each line will be read only once until the end of file, then it will start from the beginning. The only way to preserve the read line order is to use one VU -u 1.

It can be very helpful for reading very large files without storing it in memory with SharedArray

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Install xk6:
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
xk6 build --with github.com/radepopovic/xk6-read-file

Development

To make development a little smoother, use the Makefile in the root folder. It will help you create a k6 binary with your local code rather than from GitHub.

make

Once built, you can run your newly extended k6 using:

 ./k6 run -u 1 -i 200 example.js

Example

Make sure to open and close file in setup() and teardown()

// example.js
import readFile from 'k6/x/read-file';


export function setup() {
    readFile.openFile('data_to_read.txt')

}
export default function () {
    console.log(readFile.readLine());
}

export function teardown() {
    readFile.close()
}

Thanks

Thank you SharedArray and https://github.com/grafana/xk6-exec for the inspiration.

TODO

Make tests

Licence

Apache License Version 2.0

Documentation

Overview

Package read_file provides the xk6 Modules implementation for reading a file line by line concurrently in order using Javascript

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadFile

type ReadFile struct {
	// contains filtered or unexported fields
}

ReadFile represents an instance of the ReadFile module for every VU.

func (*ReadFile) Close

func (*ReadFile) Close()

func (*ReadFile) Exports

func (r *ReadFile) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exports of the JS module.

func (*ReadFile) OpenFile

func (r *ReadFile) OpenFile(filePath string)

OpenFile is a wrapper for Go read_file.OpenFile and it must be called in init context

func (*ReadFile) ReadLine

func (r *ReadFile) ReadLine() string

ReadLine is a wrapper for Go read_file.ReadLine

type RootModule

type RootModule struct{}

RootModule is the global module object type. It is instantiated once per test run and will be used to create `k6/x/exec` module instances for each VU.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface to return a new instance for each VU.

Jump to

Keyboard shortcuts

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