• Stars
    star
    1,123
  • Rank 41,432 (Top 0.9 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created almost 2 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Web Serving and Remote Procedure Calls at 50x lower latency and 70x higher bandwidth than FastAPI, implementing JSON-RPC & REST over io_uring ☎️

UCall

JSON Remote Procedure Calls Library
Up to 100x Faster than FastAPI


Discord     LinkedIn     Twitter     Blog     GitHub


Most modern networking is built either on slow and ambiguous REST APIs or unnecessarily complex gRPC. FastAPI, for example, looks very approachable. We aim to be equally or even simpler to use.

FastAPIUCall
pip install fastapi uvicorn
pip install ucall
from fastapi import FastAPI
import uvicorn

server = FastAPI()

@server.get('/sum')
def sum(a: int, b: int):
    return a + b

uvicorn.run(...)    
from ucall.posix import Server
# from ucall.uring import Server on 5.19+

server = Server()

@server
def sum(a: int, b: int):
    return a + b

server.run()    

It takes over a millisecond to handle a trivial FastAPI call on a recent 8-core CPU. In that time, light could have traveled 300 km through optics to the neighboring city or country, in my case. How does UCall compare to FastAPI and gRPC?

Setup 🔁 Server Latency w 1 client Throughput w 32 clients
Fast API over REST 🐍 1'203 μs 3'184 rps
Fast API over WebSocket 🐍 86 μs 11'356 rps ¹
gRPC ² 🐍 164 μs 9'849 rps
UCall with POSIX C 62 μs 79'000 rps
UCall with io_uring 🐍 40 μs 210'000 rps
UCall with io_uring C 22 μs 231'000 rps
Table legend

All benchmarks were conducted on AWS on general purpose instances with Ubuntu 22.10 AMI. It is the first major AMI to come with Linux Kernel 5.19, featuring much wider io_uring support for networking operations. These specific numbers were obtained on c7g.metal beefy instances with Graviton 3 chips.

  • The 🔁 column marks, if the TCP/IP connection is being reused during subsequent requests.
  • The "server" column defines the programming language, in which the server was implemented.
  • The "latency" column report the amount of time between sending a request and receiving a response. μ stands for micro, μs subsequently means microseconds.
  • The "throughput" column reports the number of Requests Per Second when querying the same server application from multiple client processes running on the same machine.

¹ FastAPI couldn't process concurrent requests with WebSockets.

² We tried generating C++ backends with gRPC, but its numbers, suspiciously, weren't better. There is also an async gRPC option, that wasn't tried.

How is that possible?!

How can a tiny pet-project with just a couple thousand lines of code compete with two of the most established networking libraries? UCall stands on the shoulders of Giants:

  • io_uring for interrupt-less IO.

    • io_uring_prep_read_fixed on 5.1+.
    • io_uring_prep_accept_direct on 5.19+.
    • io_uring_register_files_sparse on 5.19+.
    • IORING_SETUP_COOP_TASKRUN optional on 5.19+.
    • IORING_SETUP_SINGLE_ISSUER optional on 6.0+.
  • SIMD-accelerated parsers with manual memory control.

You have already seen the latency of the round trip..., the throughput in requests per second..., want to see the bandwidth? Try yourself!

@server
def echo(data: bytes):
    return data

More Functionality than FastAPI

FastAPI supports native type, while UCall supports numpy.ndarray, PIL.Image and other custom types. This comes handy when you build real applications or want to deploy Multi-Modal AI, like we do with UForm.

from ucall.rich_posix import Server
import ufrom

server = Server()
model = uform.get_model('unum-cloud/uform-vl-multilingual')

@server
def vectorize(description: str, photo: PIL.Image.Image) -> numpy.ndarray:
    image = model.preprocess_image(photo)
    tokens = model.preprocess_text(description)
    joint_embedding = model.encode_multimodal(image=image, text=tokens)

    return joint_embedding.cpu().detach().numpy()

We also have our own optional Client class that helps with those custom types.

from ucall.client import Client

client = Client()
# Explicit JSON-RPC call:
response = client({
    'method': 'vectorize',
    'params': {
        'description': description,
        'image': image,
    },
    'jsonrpc': '2.0',
    'id': 100,
})
# Or the same with syntactic sugar:
response = client.vectorize(description=description, image=image) 

CLI like cURL

Aside from the Python Client, we provide an easy-to-use Command Line Interface, which comes with pip install ucall. It allow you to call a remote server, upload files, with direct support for images and NumPy arrays. Translating previous example into a Bash script, to call the server on the same machine:

ucall vectorize description='Product description' -i image=./local/path.png

To address a remote server:

ucall vectorize description='Product description' -i image=./local/path.png --uri 0.0.0.0 -p 8545

To print the docs, use ucall -h:

usage: ucall [-h] [--uri URI] [--port PORT] [-f [FILE ...]] [-i [IMAGE ...]] [--positional [POSITIONAL ...]] method [kwargs ...]

UCall Client CLI

positional arguments:
  method                method name
  kwargs                method arguments

options:
  -h, --help            show this help message and exit
  --uri URI             server uri
  --port PORT           server port
  -f [FILE ...], --file [FILE ...]
                        method positional arguments
  -i [IMAGE ...], --image [IMAGE ...]
                        method positional arguments
  --positional [POSITIONAL ...]
                        method positional arguments

You can also explicitly annotate types, to distinguish integers, floats, and strings, to avoid ambiguity.

ucall auth id=256
ucall auth id:int=256
ucall auth id:str=256

Free Tier Throughput

We will leave bandwidth measurements to enthusiasts, but will share some more numbers. The general logic is that you can't squeeze high performance from Free-Tier machines. Currently AWS provides following options: t2.micro and t4g.small, on older Intel and newer Graviton 2 chips. This library is so fast, that it doesn't need more than 1 core, so you can run a fast server even on a tiny Free-Tier server!

Setup 🔁 Server Clients t2.micro t4g.small
Fast API over REST 🐍 1 328 rps 424 rps
Fast API over WebSocket 🐍 1 1'504 rps 3'051 rps
gRPC 🐍 1 1'169 rps 1'974 rps
UCall with POSIX C 1 1'082 rps 2'438 rps
UCall with io_uring C 1 - 5'864 rps
UCall with POSIX C 32 3'399 rps 39'877 rps
UCall with io_uring C 32 - 88'455 rps

In this case, every server was bombarded by requests from 1 or a fleet of 32 other instances in the same availability zone. If you want to reproduce those benchmarks, check out the sum examples on GitHub.

Quick Start

For Python:

pip install ucall

For CMake projects:

include(FetchContent)
FetchContent_Declare(
    ucall
    GIT_REPOSITORY https://github.com/unum-cloud/ucall
    GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ucall)
include_directories(${ucall_SOURCE_DIR}/include)

The C usage example is mouthful compared to Python. We wanted to make it as lightweight as possible and to allow optional arguments without dynamic allocations and named lookups. So unlike the Python layer, we expect the user to manually extract the arguments from the call context with ucall_param_named_i64(), and its siblings.

#include <cstdio.h>
#include <ucall/ucall.h>

static void sum(ucall_call_t call, ucall_callback_tag_t) {
    int64_t a{}, b{};
    char printed_sum[256]{};
    bool got_a = ucall_param_named_i64(call, "a", 0, &a);
    bool got_b = ucall_param_named_i64(call, "b", 0, &b);
    if (!got_a || !got_b)
        return ucall_call_reply_error_invalid_params(call);

    int len = snprintf(printed_sum, 256, "%ll", a + b);
    ucall_call_reply_content(call, printed_sum, len);
}

int main(int argc, char** argv) {

    ucall_server_t server{};
    ucall_config_t config{};

    ucall_init(&config, &server);
    ucall_add_procedure(server, "sum", &sum, NULL);
    ucall_take_calls(server, 0);
    ucall_free(server);
    return 0;
}

Roadmap

  • Batch Requests
  • JSON-RPC over raw TCP sockets
  • JSON-RPC over TCP with HTTP
  • Concurrent sessions
  • NumPy array and Pillow serialization
  • HTTPS support
  • Batch-capable endpoints for ML
  • Zero-ETL relay calls
  • Integrating with UKV
  • WebSockets for web interfaces
  • AF_XDP and UDP-based analogs on Linux

Want to affect the roadmap and request a feature? Join the discussions on Discord.

Why JSON-RPC?

  • Transport independent: UDP, TCP, bring what you want.
  • Application layer is optional: use HTTP or not.
  • Unlike REST APIs, there is just one way to pass arguments.

More Repositories

1

usearch

Fast Open-Source Search & Clustering engine × for Vectors & 🔜 Strings × in C++, C, Python, JavaScript, Rust, Java, Objective-C, Swift, C#, GoLang, and Wolfram 🔍
C++
2,081
star
2

uform

Pocket-Sized Multimodal AI for content understanding and generation across multilingual texts, images, and 🔜 video, up to 5x faster than OpenAI CLIP and LLaVA 🖼️ & 🖋️
Python
1,006
star
3

ustore

Multi-Modal Database replacing MongoDB, Neo4J, and Elastic with 1 faster ACID solution, with NetworkX and Pandas interfaces, and bindings for C 99, C++ 17, Python 3, Java, GoLang 🗄️
C++
527
star
4

udisk

The fastest ACID-transactional persisted Key-Value store designed as modified LSM-Tree for NVMe block-devices with GPU-acceleration and SPDK to bypass the Linux kernel
57
star
5

ucsb

Wide NoSQL benchmark for RocksDB, LevelDB, Redis, WiredTiger and MongoDB extending the Yahoo Cloud Serving Benchmark
C++
49
star
6

ucset

If only std::set was a DBMS: collection of templated ACID in-memory exception-free thread-safe and concurrent containers in a header-only library
C++
32
star
7

awesome

A list of awesome resources and blogs on topics related to Unum
30
star
8

NetworkXum

A NetworkX-like Python wrapper for graphs persisted in a DBMS
Python
12
star
9

CppArm

Meet the C++ and Systems Design Group of Armenia!
9
star
10

go-ustore

GoLang Packages for UKV
Go
9
star
11

examples

Learning Unum's efficient data-processing tools one cool project at a time
9
star
12

udsb

Unlimited Data-Science Benchmarks for Numeric, Tabular and Graph Workloads
Jupyter Notebook
9
star
13

coco-sm

Evaluation of Vision-Language models' multilingual properties in 20 different languages.
Python
7
star
14

usearch-benchmarks

Comparing USearch to FAISS and other Vector Search engines on Billion-scale datasets
Python
7
star
15

Docker

A set of Docker containers extensively used for both AI/HPC software development and deployment at Unum
Dockerfile
4
star
16

uform-benchmarks

Python
3
star
17

ustore-deps

UStore precompiled dependencies
Python
3
star
18

.github

GitHub Profile Header
1
star
19

press

Unum press materials
1
star
20

RegExum

A Python wrapper for persistent DBMS that simplifies large-scale text search
Python
1
star
21

PyStats2MD

Generate Markdown tables & Plotly charts from Google Benchmark outputs or directly in Python!
Python
1
star