Skip to content
项目

关于

Fast and simple backend framework for Mojo 🍇

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
+3
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

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)

探索相关项目

加载中…