Giter Club home page Giter Club logo

xk6-kv's Introduction

Key-Value Store Extension for k6

xk6-kv is a k6 extension that provides a persistent key-value store, enabling shared state across VUs during script execution. This store is persisted to disk as a single file. The extension module offers a high-read optimized store with support for up to 10,000 writes/s.

Features

  • Persistent Storage: Maintains a disk-persisted key-value store.
  • Shared Across VUs: Perfect for sharing state across VUs in your k6 scripts.
  • High-Read Optimized: While it excels in read operations, it's also capable of supporting up to 10,000 writes/s.

Why Use xk6-kv?

Ease of State Sharing: Managing state across multiple VUs can be challenging. xk6-kv alleviates this complexity by offering a straightforward way to share state, ensuring that your scripting remains as seamless as possible.

Safety First: One of the primary concerns with shared state is ensuring thread safety. With xk6-kv, you can be confident that your shared state operations are safe, thanks to its design optimized for k6's parallel VU execution model.

Lightweight Alternative: While there are other options like the redis module for state sharing, xk6-kv stands out as a more lightweight solution. It's particularly useful if you're looking for a simpler and more integrated solution without external dependencies. Though keep in mind that for extremely high-performance requirements, the redis module may offer better throughput, but for many users, xk6-kv will be more than sufficient.

Installation

To use xk6-kv, you first need to build k6 with it:

xk6 build --with github.com/oleiade/xk6-kv

Usage

import { openKv } from "k6/x/kv";

const kv = openKv();

export async function setup() {
    // (optional) Clear the key-value store to start from a clean state
    await kv.clear();
}

export default async function () {
    // Set a bunch of keys
    await kv.set("foo", "bar");
    await kv.set("abc", 123);
    await kv.set("easy as", [1, 2, 3]);
    await kv.set("a b c", { "123": "baby you and me girl"});

    console.log(`current size of the KV store: ${kv.size()}`)

    const entries = await kv.list({ prefix: "a" });
    for (const entry of entries) {
        console.log(`found entry: ${JSON.stringify(entry)}`);
    }

    await kv.delete("foo");
}

API Documentation

  • openKv(): KV: Opens a key-value store persisted on disk. Should be called only in the init context.
  • KV.set(key: string, value: any): Promise<any>: Sets a key-value pair in the store. Accepts any JSON-serializable value.
  • KV.get(key: string): Promise<any>: Retrieves a value based on its key. If the key doesn't exist, an error is thrown.
  • KV.delete(key: string): Removes a specific key-value pair from the store.
  • KV.list(options: ListOptions): Returns key-value pairs from the store filtered by the provided options.
  • KV.clear(): Removes all key-value pairs from the store. Useful when starting with a clean state, e.g., in the setup() function.
  • KV.size(): Provides the count of key-value pairs currently in the store.
  • ListOptions interface, used in KV.list(), it includes:
    • prefix: string: Filters results to keys that have the specified prefix.
    • limit: number: Restricts results to a maximum count.

xk6-kv's People

Contributors

oleiade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

deejiw

xk6-kv's Issues

Default k6 bucket is not created via openKv()

By default, k6 bucket is not being created and therefore db failed to operate.

I did add the following code snippet as per forked branch.

Since this repository does not allow public to open a new branch for pull request, I am opening this issue to address changes instead.

Thank you.

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.