Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kingluo's full-sized avatar

jinhua luo kingluo

View GitHub Profile
@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 / 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;
#!/usr/bin/env stap++
global exec_begin
global stats
probe @pfunc(ngx_epoll_process_events)
{
exec_begin = gettimeofday_us()
}
@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 / 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;
@kingluo
kingluo / cython.markdown
Last active November 27, 2017 11:07
python vs cython

case1:字节码执行

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

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

p1.py

@kingluo
kingluo / schedule.c
Created July 24, 2015 14:28
schedule performance between goroutine and pthread
king@debian:~$ time ./a.out
real 0m10.261s
user 0m3.040s
sys 0m17.312s
king@debian:~$ time go run pthread.go
real 0m4.017s
user 0m5.444s
--- testpq.go 2015-07-17 16:18:53.616212373 +0800
+++ testpq2.go 2015-07-17 16:03:03.420162955 +0800
@@ -8,6 +8,9 @@
_ "github.com/lib/pq"
)
+//#include <unistd.h>
+import "C"
+
func query(db *sql.DB, tstart time.Time, tend time.Time) {