Skip to content

Instantly share code, notes, and snippets.

View kingluo's full-sized avatar

jinhua luo kingluo

View GitHub Profile
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use std::convert::Infallible;
use std::net::SocketAddr;
async fn hello_world(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
//let path = _req.uri().path();
//let v: Vec<&str> = path.split('/').collect();
//let str = format!("hello {}", v[2]);
//Ok(Response::new(str.into()))
@kingluo
kingluo / routerify-lite main.rs
Created May 17, 2021 16:30
benchmark warp and routerify-lite when they need to match 50 urls
use hyper::{Body, Request, Response, Server};
use routerify_lite::{RequestExt, Router, RouterService};
use std::{convert::Infallible, net::SocketAddr};
async fn home_handler(_: Request<Body>) -> Result<Response<Body>, Infallible> {
Ok(Response::new(Body::from("Home page")))
}
async fn hello_handler(req: Request<Body>) -> Result<Response<Body>, Infallible> {
let user = req.param("name").unwrap();
[package]
name = "tokio-psql"
version = "0.1.0"
authors = ["Jinhua Luo <home_king@163.com>"]
edition = "2018"
[dependencies]
futures-preview = "=0.3.0-alpha.19"
tokio = "0.2.0-alpha.6"
tokio-postgres= { git = "https://github.com/sfackler/rust-postgres" }
@kingluo
kingluo / gist:3a11af38c5ecf09fbb34a01c111523ad
Last active March 14, 2018 07:16
ngx_lua systemtap安装

1. 先安装systemtap和kernel-devel

yum install systemtap kernel-devel

2. 安装debuginfo

  • 找到内核版本和glibc版本
@kingluo
kingluo / Main.java
Created January 4, 2018 08:30
flink app
package foo.bar.flinkapp;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@kingluo
kingluo / cython.markdown
Last active November 27, 2017 11:07
python vs cython

case1:字节码执行

同样的python代码,经过cython编译后运行,一般情况下也比用python解释器运行要快。

因为python解释代码,本质上就是一个for/switch,对字节码的逐条执行,相比机器语言, 使得CPU无法预判指令分支,也破坏指令缓存的局部化。

p1.py

#!/usr/bin/env stap++
global exec_begin
global stats
probe @pfunc(ngx_epoll_process_events)
{
exec_begin = gettimeofday_us()
}
@kingluo
kingluo / test.c
Created June 26, 2015 08:10
lua_newstate vs lua_newthread
$ gcc -o test test.c -llua -lm -ldl
$ time ./test state
real 0m21.470s
user 0m20.472s
sys 0m0.980s
$ time ./test
@kingluo
kingluo / test1 performance
Created March 25, 2016 09:47
trace order
$ time luajit /tmp/test.lua
real 0m4.923s
user 0m4.912s
sys 0m0.020s
@kingluo
kingluo / sample-bt-off-cpu
Created January 13, 2016 16:21
modified sample-bt-off-cpu for postgresql
#!/usr/bin/env perl
# Copyright (C) Yichun Zhang (agentzh)
# Thanks Brendan Gregg for the inspiration given here:
# http://dtrace.org/blogs/brendan/2011/07/08/off-cpu-performance-analysis/
use 5.006001;
use strict;
use warnings;