Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Log In
Found the internet!
Posts
Communities

Posts about Actix

Subreddit Icon
r/actix
870 members
A powerful, pragmatic, and extremely fast web framework for Rust
Visit
Subreddit Icon
r/rust
224k members
A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.
Visit
Subreddit Icon
r/learnrust
13.9k members
This subreddit is for asking questions about the the programming language Rust
Visit
Subreddit Icon
r/programming
5.3m members
Computer Programming
Visit
15
Subreddit Icon
•Posted by2 days ago

I am writing here in desperation after 5 weeks of intense suffering. I have been trying to learn Rust ( experienced in modern C++, python) and when I did all the code for my earliest experiments (a n-body orbit simulation tool) it works fine so the basics of the language I can handle.

But, I wanted to try to make an API to receive requests, add new objects to the orbiter, persist, and publish predicted orbits . I decided to try using Actix and diesel as it seemed to be the logical choice.

I have tried 7 different tutorials trying to make a simple API to serialize and deserialize data into and from a data base. Not a single one compiles. The one that got the closest for working is https://guimauve.io/articles/50 (even the early backend part fails completely to compile ) but I get errors saying that types do not have the generic parameters used int he tutorial and that serde::Serialzie trait is not fulfilled by a type that is not even in the code the tutorial provides. The other 6 tutorials have more than 40 error messages each. I got the last few weeks into a routine of looking for tutorials following it and finding that each one doe snot compile for a different reason.

It seems Rust libraries change almost overnight into total incompatibility and I am suffering with criptic messages of errors that made me want to go back into writing ASM. (I did wrote an equivalent solution in just 3 days of the whole thing in C++ without any framework except boost, so I cannot fathom why these libraries need to be so convoluted and change so much)

I am really starting to hate Rust, not because of the language but due to the environment being so chaotic. Can please someone point me for a tutorial that does compile and work? (my current rustc version is 1.66.0)

Please? I really do not want to develop a hatred for Rust but my willpower is starting to end.

15
28 comments
13
Subreddit Icon
•Posted by3 days ago

Hi,

My r/rust learning journey continues with full energy (ok sometimes I am lazy and don't do anything)!

This is probably my biggest learning project so far. Creating a REST API for the famous TODO app using the Actix Web framework.

I used an in-memory "database" for the moment, as I plan to tackle the usage of ORM and Rust in one of my next learnings.

Question: Should I use Diesel.rs with a PostgreSQL database?

https://blog.ediri.io/rust-development-creating-a-rest-api-with-actix-web-for-beginners

13
6 comments
10
Subreddit Icon
•Posted by2 months ago

I have the following actix test app:

#[post("/split")]
async fn split(input: String) -> Json<Vec<String>> {
    let result: Vec<String> = Regex::new(r" +")
        .unwrap()
        .split(&input)
        .map(|x| String::from(x))
        .collect();
    Json(result)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new().service(split)
    })
    .workers(100)
    .bind(("127.0.0.1", 8080))
    ?.run()
    .await
}

And I have the functionally equivalent Spring Boot endpoint:

@RestController
public class SplitController {
    private final Pattern pattern = Pattern.compile(" +");
    @PostMapping(path = "/split")
    public List<String> split(@RequestBody String input) {
        return List.of(pattern.split(input));
    }
}

I have a large text that I am submitted in the benchmark. For Spring Boot, the average response time is 119 ms. For the actix version, the average response time is a whopping 921 ms.

I just started learning Rust a few days ago, so I likely might be doing something horribly wrong.

My first thought was that compiling the regular expression every time could be the problem, but Java does this as well. So, I am clueless as to the speed difference.

What am I doing wrong or what is the deal?

UPDATE:

Based on the great feedback that I got, here is the new code:

static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r" +").unwrap());

#[post("/split")]
async fn split(input: String) -> HttpResponse {
    let result: Vec<&str> = REGEX
        .split(&input)
        .collect();
    HttpResponse::Ok().json(result)
}

I also updated the Spring Boot code to compile the regular expression only once:

@RestController
public class SplitController {
    private final Pattern pattern = Pattern.compile(" +");
    @PostMapping(path = "/split")
    public List<String> split(@RequestBody String input) {
        return List.of(pattern.split(" +"));
    }
}

The average response time over 100,000 requests:

Spring Boot - 143 ms, 1 GB RAM. I was able to get this app to run stably at 200 MB of RAM, but the average response time was 422 ms. This is with the default embedded Tomcat server. Less RAM and it starts failing.

actix - 58 ms, 80 MB RAM. There could still be some tuning for actix that I don't know about.

Thanks to everyone who helped out this Rust noob!

UPDATE 2:

Special thanks to u/Imaginos_In_Disguise for pointing out a copy-paste error I did in the Spring Boot code that was artificially making it faster because it was not actually processing the payload. After fixing that, the Spring Boot code was WAY, WAY slower.

10
41 comments
26
Subreddit Icon
•Posted by2 months ago

Hey r/rust!

We've got some exciting news for you! Shuttle just got a whole lot better with the latest release. Here's what's new:


  • Actix support: we’ve added support for the actix framework, meaning you’ll be able to deploy your actix app in no-time.

  • Static file support: shuttle now supports serving static files like HTML, CSS, and JavaScript which makes it possible for you to deploy the whole package, rather than just the backend.

  • Public dependencies: it's now super easy to include public dependencies in your shuttle projects. Just specify them in your Cargo.toml file and we'll take care of the rest.

  • Better scaffolding: the CLI now has a completely interactive starter flow!

  • And more: we've also included several other improvements and bug fixes.

The full release notes can be found here: https://github.com/shuttle-hq/shuttle/releases/tag/v0.8.0

We can't wait to see what you build with these new features. Let us know what you think in the comments!

26
11 comments
16
Subreddit Icon
•Posted by3 months ago
16
14 comments
112
Subreddit Icon
•Posted by5 months ago
112
17 comments
31
13
Subreddit Icon
•Posted by4 months ago
13
0 comments