Skip to content

Instantly share code, notes, and snippets.

View iAnatoly's full-sized avatar

Anatoly Ivanov iAnatoly

View GitHub Profile
@iAnatoly
iAnatoly / UDR-UDT.md
Last active March 16, 2022 21:04
Quicky Transferring large viles over high-latency WAN link using UDR/UDT

Motivation

At some point, you might find yourself in need to transfer a file (i.e. a dump of the database, or a backup tarball) quickly over a WAN link. Unfortunately, regular copy speeds are impaired by TCP protocol and latency and speed of light - and link bandwidth has very limited effect on the transfer speeds. However, there is a workaround: one can use UDP-based file transfer (UDT). Here is a proof-of-concept experiment that demonstrates the transfer speed improvement.

Experiment

Create a large file to transfer:

@iAnatoly
iAnatoly / kube_client_cert_validity.sh
Last active December 7, 2021 17:10
check kube client cert validity period
cat ~/.kube/config | grep client-certificate | sed -e ‘s/ client-certificate-data: //’ | base64 -d | openssl x509 -in - -noout -text
@iAnatoly
iAnatoly / bpftrace.sh
Created March 24, 2021 21:10
bpftrace oneliners
# see https://github.com/iovisor/bpftrace/blob/master/docs/tutorial_one_liners.md
# histogram for udp_recvmsg timing
sudo bpftrace -e 'kprobe:udp_recvmsg { @start[tid] = nsecs; } kretprobe:udp_recvmsg /@start[tid]/ { @ns[comm] = hist(nsecs - @start[tid]); delete(@start[tid]); }'
# histogram for retval of udp_recvmsg (which is message size in bytes)
sudo bpftrace -e 'kretprobe:udp_recvmsg { @bytes[comm] = hist(retval); }'
@iAnatoly
iAnatoly / softnetstat.py
Created March 24, 2021 18:01
Ad-hoc monitoring for time_squeeze changes in /proc/net/softnet_stat
#!/usr/bin/env python3
#
# Ad-hoc monitoring for time_squeeze changes in /proc/net/softnet_stat .
#
# usage: ./softnetstat.py <refresh_interval_seconds>
#
# see https://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/
#
from time import sleep
from datetime import datetime
@iAnatoly
iAnatoly / whattheswap.sh
Last active November 30, 2021 18:47
print out the swap usage by process
for proc in /proc/*; do cat $proc/smaps 2>/dev/null | awk -v proc="${proc}" '/Swap/{swap+=$2/1024}END{if (swap>1) { "readlink "proc"/exe"|getline c; print int(swap+0.5), "\tMB\t", c }}'; done | sort -n
@iAnatoly
iAnatoly / swapin-swapout.bt
Created February 8, 2021 20:55
bpftrace oneliner for swap-in and swap-out
bpftrace -e 'kprobe:swap_read*,kprobe:swap_write* {@[comm, pid] = count();} interval:s:5{ time(); print(@); clear(@); }'
@iAnatoly
iAnatoly / gist:022834cf07ec0d83cb14eae054864aba
Created November 10, 2020 01:13
Influxdb retention policy and downsampling
> CREATE RETENTION POLICY two_days on weather duration 2d replication 1 default
> CREATE RETENTION POLICY year on weather duration 52w replication 1
> create continuous query cq_30m on weather BEGIN SELECT mean(*) into year.:MEASUREMENT from two_days./.*/ group by time(30m),* EN
SELECT temp *9/5+32
FROM
(SELECT median("temperature") AS "temp" FROM "weather" WHERE $timeFilter GROUP BY time(5m)),
(SELECT median("mean_temperature") AS "temp" FROM "year"."weather" WHERE $timeFilter GROUP BY time(1h))
GROUP BY "source" fill(null)
@iAnatoly
iAnatoly / respbery_wifi.sh
Created November 5, 2019 19:54
Fix raspbery pi wifi reconnevct
cp /etc/wpa_supplicant/ifupdown.sh /etc/ifplugd/action.d/ifupdown
@iAnatoly
iAnatoly / fix-ubuntu-wifi-on-resume.sh
Created November 5, 2019 02:28
Fix no wifi on resume in Ubuntu
# cat > /etc/systemd/wifi-resume.service
[Unit]
Description=Restart networkmanager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target
[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service