Skip to content

Instantly share code, notes, and snippets.

View snavruzov's full-sized avatar

Sardor Navruzov snavruzov

  • SMARTER Group, Inc.
  • Tashkent, UZ
View GitHub Profile
@snavruzov
snavruzov / nginx-tuning.md
Created April 29, 2022 07:07 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

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.

  • Maximum Open Files
You requested maxclients of 10000 requiring at least 10032 max file descriptors.
Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
@snavruzov
snavruzov / InactivityLogout.py
Created August 18, 2021 12:44 — forked from dryan/InactivityLogout.py
Django middleware for extending session expiration on access
class InactivityLogout(object):
def process_request( self, request ):
from datetime import datetime, timedelta
from django.conf import settings
COOKIE_AGE = getattr(settings, 'SESSION_COOKIE_AGE', 7200)
if datetime.now() – request.session.get_expiry_date() < timedelta(seconds = COOKIE_AGE):
request.session.set_expiry(datetime.now() + timedelta(seconds = COOKIE_AGE))
return None # pass through
@snavruzov
snavruzov / docker-compose-kafka.yaml
Created March 5, 2019 09:28
Hyperledger Fabric Kafka consensus based network
version: '2'
networks:
dcode:
services:
zookeeper0:
extends:
file: docker-compose-base.yml
@snavruzov
snavruzov / adoption.js
Created July 2, 2018 14:45
Pet Adoption smart-contract in Solidity
pragma solidity ^0.4.17;
contract Adoption {
address[16] public adopters;
function owners() public view returns (address) {
return adopters;
}
@snavruzov
snavruzov / pow.js
Last active July 3, 2018 07:05
Pseudocode of PoW
function proof_of_work(self, last_proof) {
/**
Найти такое число B который hash(AB) содержит последующие 10 нулей
где A есть предыдущее значение B
A - предыдущее доказательство
B - новое доказательство
**/
proof = 0;
while validate_proof(last_proof, proof) is False:
proof += 1; //nonce
@snavruzov
snavruzov / celery.sh
Created June 28, 2018 06:36 — forked from amatellanes/celery.sh
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@snavruzov
snavruzov / migrate-redis.py
Created April 11, 2016 15:10 — forked from thomasst/migrate-redis.py
Migrate Redis data on Amazon ElastiCache
"""
Copies all keys from the source Redis host to the destination Redis host.
Useful to migrate Redis instances where commands like SLAVEOF and MIGRATE are
restricted (e.g. on Amazon ElastiCache).
The script scans through the keyspace of the given database number and uses
a pipeline of DUMP and RESTORE commands to migrate the keys.
Requires Redis 2.8.0 or higher.
@snavruzov
snavruzov / Node.py
Created June 25, 2013 09:30
Binary Tree
__author__ = 'root'
class Node:
data, left, right, = 0, None, None
def __init__(self, data):
self.data = data
self.left = None
self.right = None