[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace serde_json with sonic_rs for poem crate #819

Merged
merged 7 commits into from
Sep 7, 2024

Conversation

Mr-Leshiy
Copy link
Contributor

Refactored poem crate, replaced at some places usage of serde_json with the more faster json serde crate sonic_rs.

I've locally benchmarked a simple poem service like this

use poem::{handler, listener::TcpListener, post, web::Json, Route, Server};

#[handler]
fn echo(val: Json<serde_json::Value>) -> Json<serde_json::Value> {
    val
}

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    let app = Route::new().at("/echo", post(echo));
    Server::new(TcpListener::bind("0.0.0.0:3000"))
      .run(app)
      .await
}

With the help of locust I've got a 20% decrease of response time, with the following benchmark.

from locust import FastHttpUser, task
import json

# Opening JSON file
f = open('large-file.json')
data = json.load(f)


class HelloWorldUser(FastHttpUser):
    @task
    def hello_world(self):
        self.client.post(
            "/echo",
            json=data
        )

large-file.json

Issue

#813

@attila-lin
Copy link
Collaborator

How about be a feature?

Someone may not care about the performance.

@Mr-Leshiy
Copy link
Contributor Author

@attila-lin updated it with adding a new feature flag sonic-rs.
Should I also put some notes in somewhere in docs about this new feature ?

@Mr-Leshiy
Copy link
Contributor Author

@attila-lin
So sorry for the delay, forgot about this PR.
I've updated corresponded README.md files and rust docs.

@attila-lin
Copy link
Collaborator

I'd like to merge this. Any suggestions? @sunli829

@sunli829
Copy link
Collaborator
sunli829 commented Sep 2, 2024

does sonic-rs only work with nightly Rust?

@Mr-Leshiy
Copy link
Contributor Author

@sunli829 no, it works on stable one

@sunli829 sunli829 merged commit 6d08604 into poem-web:master Sep 7, 2024
5 of 7 checks passed
@Mr-Leshiy Mr-Leshiy deleted the feat/move_from_serde_json branch September 9, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants