Skip to content
Proyek

Tentang

Fast and simple backend framework for Mojo πŸ‡

Pengembangan web dan aplikasi

Cara angka ini diukur

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
0
dalam 15 hari
+3
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

Mojelly Framework πŸ‡

⭐ Starred by @lattner β€” creator of LLVM, Swift, and Mojo

Thank you, Chris :)

πŸ‡ Mojelly

Fast async backend framework for Mojo

Mojo License PRs Platform

About Mojelly ❔

Mojelly - Fast async opensource backend framework for Mojo πŸ‡! Mojelly started as Limnetic's (creator, me :D) pet-project which was created for test of Mojo's speed with Zero-Copy FFI with C. And Mojo is young lang, very powerful with simple syntax. So, it was cool challenge for me. Mojelly is created to be fast-enough, simple to use and easy to contribute, that makes it good choice to you to join the project!

Logging πŸ“

Per-request logging is off by default (it costs ~20% throughput). Enable it at startup:

MOJELLY_LOG_LEVEL=1 ./server

Worker threads 🧡

By default Mojelly starts one worker per CPU the process is allowed to use (so taskset and container cpusets are respected) and pins each worker to one of those CPUs. Override the count with MOJELLY_THREADS:

MOJELLY_THREADS=4 ./server

Limits and timeouts πŸ›‘οΈ

Safe defaults, overridable with environment variables at startup:

Variable Default Meaning
MOJELLY_MAX_HEADER_SIZE 65536 URL + headers of one request, bytes (over β†’ 431)
MOJELLY_MAX_BODY 10485760 request body, bytes (over β†’ 413)
MOJELLY_IDLE_TIMEOUT 60 seconds without traffic before a connection is closed (0 = off)
MOJELLY_REQUEST_TIMEOUT 30 seconds allowed to receive one complete request (0 = off)

Timeouts are checked once a second, so they are accurate to about one second.

Performance CI πŸ“ˆ

Every PR to main or dev is benchmarked by .github/workflows/perf.yml: the PR head, dev and main are built and measured one after another on the same runner, and the result is posted as a PR comment. For each scenario (/json with 100 and 500 connections, a new connection per request, browser-like headers and cookies, a larger /html body) it shows requests/s, p99 latency and server CPU per request, and the PR's change against dev and main. The job fails if the PR is more than 15% slower than its base branch and the change is larger than the run-to-run noise.

Run it locally (needs oha and a built ./server in each directory):

python3 scripts/perf_run.py --build main=../main --build dev=../dev --build pr=. --out results.json
python3 scripts/perf_report.py results.json --pr pr --base dev

What we use βš™οΈ

Mojo language C language Bash (for build.sh) llhttp libuv (soon maybe will be change to io_uring) openssl (not yet) pthread gcc compiler emberjson multipart parser by iafonov

Mojelly's logo πŸ–ΌοΈ

Mojelly's logo is a GRAPE! πŸ‡πŸ‡πŸ‡

(Idk why, "jelly" sounds cool and I associate with grapes)

⚠️ WARNING: FRAMEWORK (as like as Mojo) WORKS ONLY ON LINUX! USE WSL OR LINUX DISTRO. Pls test it on MacOS

Here is simplest server with Mojelly:

from mojelly.http.request import HTTPRequest
from mojelly.http.response import HTTPResponse
from mojelly.core.router_handlers import RouterHandlers

# Hello world plain text response
def hello_world(mut req: HTTPRequest) -> HTTPResponse:
    return HTTPResponse(200, "Hello, World")


def main():
    var router = RouterHandlers()

    router.get("/", hello_world)

    var server = HTTPServer(router)
    server.listen(8080)
    server.run()

After this, run build.sh πŸ› οΈ:

bash build.sh

It will generate build/app_generated.mojo and auto-compile it to server binary file. Then, you can run your server! πŸ™‚

./server

Normally is looks like that:

❯ bash build.sh 
πŸ”§ Using pixi environment...
πŸ”₯ Using Mojo via pixi:
Mojo 1.2.0 (2016d0cd)

πŸ” Checking C core...
πŸ“¦ libmojelly.a not found, building...
πŸ”¨ Building C core with -O3...
βœ… bridge.o built
βœ… multipart_parser.o built
βœ… libmojelly.a rebuilt!
-rw-r--r-- 1 limnetic limnetic 96290 ноя 22 13:29 lib/libmojelly.a

πŸ“’ Calling for server-code generator...
πŸ”§ Generating server code...
   Mode: MULTITHREADED
βœ… Generated: build/app_generated.mojo
πŸ“¦ Run: ./build.sh

πŸ“¦ Building server...

βœ… Server built! Run ./server

   To run:
   ./server

❯ MOJELLY_THREADS=4 MOJELLY_LOG_LEVEL=1 ./server
πŸ‡ Mojelly HTTP Server (Multithreaded)
[C] βœ… All 4 threads created
βœ… Worker threads started
πŸš€ Server listening on port 8080
[C] 🧡 Thread 2 listening on CPU 2 (port 8080)
[C] 🧡 Thread 3 listening on CPU 3 (port 8080)
[C] 🧡 Thread 1 listening on CPU 1 (port 8080)
[C] 🧡 Thread 0 listening on CPU 0 (port 8080)
[13:31:44] [T0] GET / 200 0.01ms
[13:31:46] [T1] GET /qwerty 404 0.00ms

If you are interested, please ⭐ this project :) Thank you! πŸ‡

IF YOU WANT TO ASK ME SOMETHING, PLEASE, WRITE ME IN DISCORD OR TELEGRAM (@limneticgg)

Jelajahi proyek terkait

Memuat…