Skip to content

Instantly share code, notes, and snippets.

View v0112358's full-sized avatar

Nguyen Tan Vy v0112358

  • Freelancer
  • Vietnam
View GitHub Profile
@v0112358
v0112358 / h2load-nginx-static-file-with-local-and-nfs.md
Created February 20, 2022 03:23
h2load-nginx-static-file-with-local-and-nfs.md

Local storage

[root@srvsg2 ~]# h2load -n 100000 -c 100 -t 1 -T 5 -m 10 -H 'Accept-Encoding: gzip,deflate' https://xxx.svc-linode.xxx.com/wp-content/uploads/2015/11/logo-1.png
starting benchmark...
spawning thread #0: 100 total client(s). 100000 total requests
TLS Protocol: TLSv1.2
Cipher: ECDHE-RSA-AES256-GCM-SHA384
Server Temp Key: ECDH P-256 256 bits
Application protocol: h2
@v0112358
v0112358 / Prometheus-Consul-Postgres.yml
Created February 18, 2022 07:33
Prometheus-Consul-Postgres.yml
global:
scrape_interval: 10s
external_labels:
Environment: sandbox
Region: gcp
Source: prometheus
scrape_configs:
- job_name: consul-services
metrics_path: "/metrics"
@v0112358
v0112358 / pbm_mongodb_3.6.23.md
Created September 1, 2021 01:39
get current storage status: query mongo: mongo: no documents in result

MongoDB info

  • MongoDB version: 3.6.23
  • PBM version: 1.6.0
  • Error messages:
Sep  1 07:47:17 vm-prod-mongodb-2 pbm-agent: 2021-09-01T07:47:17.000+0700 I got command backup [name: 2021-09-01T00:47:16Z, compression: s2] <ts: 1630457236>
Sep  1 07:47:17 vm-prod-mongodb-2 pbm-agent: 2021-09-01T07:47:17.000+0700 I got epoch {0 0}
@v0112358
v0112358 / Slow startup MySQL 5.7 with innodb_numa_interleave.md
Last active March 11, 2021 05:23
Slow startup MySQL 5.7 with innodb_numa_interleave=ON
  • innodb_numa_interleave=OFF
# time systemctl restart mysqld

real	0m18.380s
user	0m0.007s
sys	0m0.005s
2021-03-11T11:25:45.500980+07:00 0 [Note] InnoDB: Uses event mutexes
@v0112358
v0112358 / Benchmarking local SSD performance on GCP.md
Last active March 8, 2021 05:04
Benchmarking local SSD performance on GCP

Latency

ioping -WWW -c 200 -i 0 -L -s 4K /mnt/
...
--- /mnt/ (xfs /dev/nvme0n1) ioping statistics ---
199 requests completed in 14.1 ms, 796 KiB written, 14.1 k iops, 55.3 MiB/s
generated 200 requests in 16.1 ms, 800 KiB, 12.5 k iops, 48.7 MiB/s
min/avg/max/mdev = 61.4 us / 70.7 us / 273.9 us / 16.9 us
@v0112358
v0112358 / mysql_memory_calculator.md
Last active December 30, 2023 13:34
MySQL Memory Calculator

MySQL 5.6

Base memory

SELECT ( @@key_buffer_size
+ @@query_cache_size
+ @@innodb_buffer_pool_size
+ @@innodb_log_buffer_size
+ @@innodb_additional_mem_pool_size )
/ (1024 * 1024 * 1024) AS BASE_MEMORY_GB;

How does pgpool-II handle md5 authentication?

1. PostgreSQL and pgpool stores md5(password+username) into pg_authid or pool_password. From now on I denote string md5(password+username) as "S".
2. When md5 auth is requested, pgpool sends a random number salt "s0" to frontend.
3. Frontend replies back to pgpool with md5(S+s0).
4. pgpool extracts S from pgpool_passwd and calculate md5(S+s0). If #3 and #4 matches, goes to next step.
5. Each backend sends salt to pgpool. Suppose we have two backends b1 and b2, and salts are s1 and s2.
6. pgpool extracts S from pgpool_passwd and calculate md5(S+s1) and send it to b1. pgpool extracts S from pgpool_passwd and calculate md5(S+s2) and send it to b2.
7. If b1 and b2 agree with the authentication, the whole md5 auth process succeeds.
@v0112358
v0112358 / postgresql_wal_archiving_with_compression.md
Created July 24, 2020 07:27
postgresql_wal_archiving_with_compression

1/ Enable wal archiving (need to restart PostgreSQL)

cat postgresql.conf
....
archive_mode = always
archive_command = 'test ! -f /wal_archive/%f.zst && pzstd -o /wal_archive/%f.zst %p'
....

2/ Monitor wal archiving

@v0112358
v0112358 / Install-pgagroal-on-CentOS7.md
Last active May 7, 2020 03:51
Install pgagroal on CentOS 7

pgagroal

pgagroal is a high-performance protocol-native connection pool for PostgreSQL.

Install

yum install centos-release-scl
yum install cmake3 libev libev-devel openssl openssl-devel python36-docutils
yum install devtoolset-8
scl enable devtoolset-8 bash
@v0112358
v0112358 / Upgrade-plugin-for-provider-digitalocean.md
Created May 6, 2020 03:22
Upgrade terraform provider to use digitalocean_vpc resource

The error message:

Error: Invalid resource type

  on vpc-prod-cicd-k8s.tf line 1, in resource "digitalocean_vpc" "vpc_prod_cicd_k8s":
   1: resource "digitalocean_vpc" "vpc_prod_cicd_k8s" {

The provider provider.digitalocean does not support resource type
"digitalocean_vpc".