寫好Log對我而言一直是一項重要的技能, 因為它可以讓問題發生時, 讓開發者用最短的時間找到並解決問題… 剛好在Hacker News上看到這篇 Logging in Python like a PRO , 順便紀錄一下這位作者的一些觀點…
好的Log所需具備的特性
* Descriptive * Contextual * Reactive
They’re descriptive in the sense that they give you a piece of information, they’re contextual because they give you an overview of the state of things at the moment, and finally, they’re reactive because they allow you to take action only after something happened (even though your logs are sent/consumed real-time, there’s not really something you can do to change what just happened).
# using a temporary directory to download the dehydrated
cd ~/tmp
wget "https://raw.githubusercontent.com/dehydrated-io/dehydrated/master/dehydrated"
chmod +x dehydrated
sudo mv dehydrated /usr/local/bin/
Dehydrated環境設定
# create directories that dehydrated will need
sudo mkdir -p /etc/dehydrated /var/www/dehydrated
#change to the dehydrated dir
cd /etc/dehydrated
# setup the config
echo 'OCSP_MUST_STAPLE=yes' | sudo tee -a config
echo 'KEYSIZE=2048' | sudo tee -a config
echo 'WELLKNOWN=/var/www/dehydrated' | sudo tee -a config
# setup the domain file
echo 'blog.gechen.org' | sudo tee -a domains.txt
server {
listen 80;
server_name blog.gechen.org;
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name blog.gechen.org;
index index.php;
ssl_certificate /etc/dehydrated/certs/blog.gechen.org/fullchain.pem;
ssl_certificate_key /etc/dehydrated/certs/blog.gechen.org/privkey.pem;
# ... skip some configs
# this part is for dehydrated
location /.well-known/acme-challenge/ {
alias /var/www/dehydrated;
}
}
執行Dehydrated 來更新Let’s encrypt certs
如果是第一次使用 dehydrated 則要額外執行下面指令
sudo dehydrated --register --accept-terms
透過下面的指令來做Let’s encrypt certificate的申請/更新
# the following command will apply/renew certificates for the domains in file: /etc/dehydrated/domains.txt
sudo dehydrated -c
# or we can also directly use command below to apply for specific domain certificate
sudo dehydrated -c -d blog.gechen.org
clients -> HTTP API -> Lambda function -> Dynamo DB
直接跳到測試結果
Cold start:
* All languages(except Java and .Net) have a pretty small cold start. * Java even cannot start with 128Mb. It needs more memory. But GraalVM can help in this case. * Rust beats all runtimes for all setups for cold start, the only exception is 128 MB where Python is the best.
* Golang and Rust are the winners. They have the same brilliant performance. * .Net has almost the same performance as Golang and Rust, but only after 1k iterations(after JIT). * GraalVM has a stable great performance almost the same as .Net and a bit worse than Rust and Golang. But it doesn’t perform well for the smallest setup. * Java is the next after GraalVM.The same as .Net, Java needs some time(1–3k iterations) for JIT(C1). Unfortunately for this particular use case, I was not able to achieve the expected great performance after JIT C2 compilation. Maybe AWS just disabled it. * Python has stable good performance but works too slow for the 128 MB. * Ruby has almost the same performance as Python, but we see some duration growing after 20 min invocations(after 15k iteration). * NodeJs is the slowest runtime, after some time it becomes better(JIT?) but still is not good enough. In addition, we see the NodeJS has the worst maximum duration.
可以簡單透過curl 指令,來發起一個http的request到我們剛啟用的socks5 server port上。 如果成功的話,理論上會看到我們預期的html 網頁了。
Step 5. 設定SwitchyOmega
這是一個browser extension,主要是可以讓我們連接不同的網頁時,可以使用預先設定好的條件或方式來連接。 舉例來說,我們可以設定當接http://192.168.10.2:8080這個位址時,就自動透過我們預先設定好的socks5 server 與jump server 連接,此外,它還可以透過wildcard的方式來導流特定網段或特定domain 的網頁。