Skip to content

Instantly share code, notes, and snippets.

@salehirandom
salehirandom / gsize.py
Last active April 7, 2025 22:51
Find actual size of file insize gzip compressed file
#!/bin/python
import gzip
import sys
import os
def human_readable_size(size_bytes):
for unit in ['B','KB','MB','GB','TB']:
if size_bytes < 1024:
return f"{size_bytes:.2f} {unit}"
@salehirandom
salehirandom / nginx-tuning.md
Created October 16, 2024 04:32 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

[docker]
project = warehouse
app_dir = /%(project)
chdir = %(app_dir)
wsgi-file = django-config/wsgi.py
static-map = /static=/%(project)/static
enable-threads = true
single-interpreter = true
import ipaddress
_iran_cidr = []
with open('IR.txt', 'r') as f:
for line in f:
_iran_cidr.append(ipaddress.IPv4Network(line.strip()))
with open('find.list', 'r') as f:
for line in f:
_ip = line.strip()
_ip_cidr = ipaddress.IPv4Network(_ip)
@salehirandom
salehirandom / tc-mark.nft
Created June 2, 2024 01:38 — forked from gaoyifan/tc-mark.nft
Traffic control mark with nftables
#! /usr/sbin/nft -f
chain tc-wan {
# check default priority
mark & 0xff0 == 0x130 ip dscp set af22 return
# real-time application
## Dota2
udp dport 27000-27200 \
meta mark set mark & 0xfffff00f ^ 0x110 ip dscp set af41 return
{
"max-concurrent-uploads": 1,
"max-concurrent-downloads": 1,
"iptables": false,
"registry-mirrors": [
"https://docker.arvancloud.ir",
"https://registry.docker.ir"
]
}
@salehirandom
salehirandom / php-pools.md
Created October 15, 2023 21:41 — forked from holmberd/php-pools.md
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@salehirandom
salehirandom / fibonacci.py
Created December 21, 2022 11:49 — forked from dwy6626/fibonacci.py
Timeit!
import time
from functools import lru_cache
import numpy as np
from matplotlib import pyplot as plt
from decimal import Decimal, getcontext
getcontext().prec = 250