Saturday, March 19, 2022
Rust- Generic type T is super set of &T and &mut T
Saturday, February 5, 2022
May be Rust can speed Django projects ?
Step1: create the Rust program as library using pyo3 and build the file using cargo build. Remember to put the crate-type "cdylib". I used manual build and copy .so file . Remember to keep the python module name and .so file name as same. https://pyo3.rs/v0.15.1/ Step2 Create your normal Django helloworld App Step3 Copy the .so file to your Django project folder and import it in your views.py file, then you should be able to run django server .
Saturday, March 27, 2021
Load tested my Django site
Benchmark HTTP Latency with wrk
Recently I started reading through Actix-web, Django,tokio etc, so thought of bench marking the latency. Started with Django as it is pretty easy get started and its in python.
looks like wrk ( https://github.com/wg/wrk ) is a good tool to start with.
"wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue."
Installation also pretty easy in Ubuntu:
1. sudo apt-get install build-essential libssl-dev git -y
2. git clone https://github.com/wg/wrk.git wrk
3. cd wrk/
4. sudo make
5. sudo cp wrk /usr/local/bin
Run your Django server using
python manage.py runserver
then another terminal you can run your wrk as below
wrk -t12 -c400 -d30s --latency http://127.0.0.1:8000
I only had single page and not much custom files in the Django and not data base request. Not sure this is a good response .. Please share your comments.
Also got something like this Django logs as well.
[27/Mar/2021 17:39:14] "GET / HTTP/1.1" 200 196
[27/Mar/2021 17:39:14] "GET / HTTP/1.1" 200 196
Exception happened during processing of request from ('127.0.0.1', 33856)
[27/Mar/2021 17:39:14] "GET / HTTP/1.1" 200 196
[27/Mar/2021 17:39:14] "GET / HTTP/1.1" 200 196
I am planning to try this same experiment with actix-web and Rust , will share once I have something..
Wednesday, January 6, 2021
Yew App - Sudoku solver
How would be a Yew app Sudoku solver ?
sudoku solver can basically be a backtracking algorithm . Last month I implemented a Rat-Maze problem solver with Yew App. But it does not look visually much attractive to some of my friends. So thought of doing a sudoku solver with same code modifying the logic for sudoku.
Demo video
if you are interested to see the code, it here ( Note: its an ugly code)
Tuesday, December 29, 2020
Rat-Maze problem - Yew app - PART2
Rust Yew app:
Last week I wrote about the Rat-Maze problem - Yew app.
Writing code in Rust programming language is always fun and a learning.So thought of making some enhancements to the yew app
1. add colors to the cells
2. after solving the path, change the color of the cells in the path. ..etc
This gave an opportunity to work with CSS and Yew. I think still there is no full support for CSS from Yew as you might have seen in React. But I was managed to change the color with "class" property in CSS.
index.css
lib.rs
Source Code:
How to compile and run:
output:
![]() |
Saturday, December 26, 2020
Rat-Maze problem - Yew app built with rustwasm
Backtracking Algorithms
I just started loving the algorithms , especially backtracking algorithms.This geekforgeeks page gives more details on backtracking
https://www.geeksforgeeks.org/rat-in-a-maze-backtracking-2/
Solving this problem in Rust programming will be a little more interesting. Even more fun if we can build this as Rust Wasm app. Webassembly (wasm) is one of the latest technology that web developers are interested in. So thought of building the rat-maze as a Yew app.
Yew is a modern Rust framework for creating multi-threaded front-end web apps with WebAssembly
Read mroe about Yew here - https://yew.rs/docs/en/
I used following dependencies -
Backtracking -
This is one of the algorithm every programmer should try and understand. It will involve recursion and push and pop values from Results.
In my program, "solve" is the method actually implemented this backtracking
Yew Component:
The full program is below for your reference:
Output:
Wednesday, December 9, 2020
How to make dereference for your struct in Rust
Dereference operator ( *) in Rust
Dereference operator we have seen in C programming language. Yes , I am talking about the ' * ' operator that we use for dereferencing a pointer in C.
I am not sure how * operator works behind the seen, but the it dereference the pointer and give us the value in that address.
But in Rust implementation is more obvious that the type has to implement the trait 'Deref".
https://doc.rust-lang.org/std/ops/trait.Deref.html
So let's see how should be convert our struct to dereference the value whatever way that we like.
This is simple program to use * operator on MyStruct. And it is only to demonstrate the capabilities of Deref trait, not an idiomatic code.
Here we are derefencing the second field value when we use * operator on MyStruct instance.
use std::ops::Deref; struct MyStruct{ x: i32, y:String, } impl Deref for MyStruct{ //the Deref trait implementation should have Target //associated type type Target = String; // trait mandotory function implementation fn deref(&self) -> &Self::Target{ &self.y } } fn main(){ let my = MyStruct { x:4,y:"hello".to_string() }; //derefencing our struct with * operator println!("{}",*my); }
Conclusion:
Even though references and dereferencing are essential part of most of the system programming languages, how they are implemented are always hidden behind the language implementations ( in my knowledge) . But Rust gives that insight and flexibility to use them on custom references.


