Abort instead of panicking

Error-handling code also requires space and can affect performance. If you try to write microservices that won't panic, and will try to solve problems, and fail only when there's an unsolvable problem, you can consider using aborts (immediate termination of the program without unwinding the stack), instead of Rust's panic.

To activate it, add the following to your  Cargo.toml file:

[profile.release]
panic = "abort"

Now, if your program fails, it won't make a panic and will be stopped immediately without printing backtraces.

Aborting is dangerous. If your program will be aborted, it has less chance to write logs corectly or deliver spans to distributed tracing. For microservices, you can create a separate thread for tracing, and even if the main thread failed, wait till all available tracing records will be stored.

Sometimes, you not only need to improve the performance, but also have to reduce the size of the binary. Let's see how to do it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.237.131