GithubHelp home page GithubHelp logo

gelbpunkt / zangy Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 1.0 129 KB

A fast redis library for python and asyncio written in Rust

License: MIT License

Rust 92.63% Python 5.38% Shell 1.04% Dockerfile 0.95%
pyo3 python redis rust

zangy's Introduction

zangy

A fast redis library for python written in Rust using PyO3.

Installation

pip install --user zangy

Building from source requires nightly Rust.

How does it work?

zangy aims to be the fastest python redis library. This is done by using pyo3 to generate shared objects in binary form. It is pretty much identical to writing this in C, but less of a pain to compile and identical in speed.

Due to being completely in Rust, zangy can't do lifetime-based connection pooling and instead will create connections on startup and not lazily. All actions are distributed over the pool based on round robin. Internally, redis-rs is used for the redis operations and tokio is used to spawn tasks outside the GIL.

Because it uses tokio and rust-level tasks, zangy unleashes maximum performance when used with a lot of concurrent things to do.

Is it fast?

Yes! It beats similar Python libraries by a fair margin. Tokio, no GIL lock and the speed of Rust especially show when setting 1 million keys in parallel.

Benchmark sources can be found in the bench directory.

Benchmarks below done with Redis 7.0.8 and Python 3.11.1, redis-py 4.4.2 and the latest zangy master using a pool with 10 connections:

Task redis-py zangy
1.000.000 sequential GET 2min 34s 1min 44s
1.000.000 sequential SET 2min 45s 1min 52s
1.000.000 parallel SET Pool times out after 18min 52s 17s

TLDR: zangy is faster in every regard but crushes in actually concurrent scenarios.

Usage

The API is subject to change.

import zangy
# Create a pool with 2 connections and 2 pubsub connections
pool = await zangy.create_pool("redis://localhost:6379", 2, 2)
# Generic redis commands (disadvised)
await pool.execute("SET", "a", "b")
# Individual commands
value = await pool.get("a")

# Wait for pubsub messages and echo back
with pool.pubsub() as pubsub:
    await pubsub.subscribe("test1")
    async for (channel, payload) in pubsub:
        print(channel, payload)
        await pool.publish("test2", payload)

Aliases for almost all operations exist on pool (.set, .set_ex, .zrange, etc).

What is not supported?

  • Single connections. Just use a pool with 1 member.

zangy's People

Contributors

gelbpunkt avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

mardix

zangy's Issues

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.