Skip to content

Instantly share code, notes, and snippets.

View pfreixes's full-sized avatar

Pau Freixes pfreixes

  • Github
  • Barcelona
View GitHub Profile
@pfreixes
pfreixes / gist:3187511
Created July 27, 2012 11:36
Supervisorctl bash autocomplete
# pfreixes, 2012-07-27
# Add to /etc/bash_completion.d/supervisorctl
_supervisor()
{
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
@pfreixes
pfreixes / read.go
Last active August 12, 2021 15:56
Test for checking maximum throughput of random reads over a 40GB file stored in a SSD disk
package main
import (
"fmt"
"math/rand"
"os"
"sync"
"time"
)
@pfreixes
pfreixes / Gevent vs asyncio with libuv.md
Last active May 16, 2021 08:17
Gevent vs asyncio with libuv

The numbers claimed by this benchamark about Gevent [1] comparaed with the numbers got by Asyncio with the uvloop and even with the default loop has left me a bit frozen. Ive repeated a few of them : gevent, asyncio, asyncio-uvloop and go for the echo server and these are the numbers roughly:

For gevent

$ ./echo_client
685393 0.98KiB messages in 30 seconds
Latency: min 0.04ms; max 4.48ms; mean 0.126ms; std: 0.048ms (37.68%)
Latency distribution: 25% under 0.088ms; 50% under 0.122ms; 75% under 0.158ms; 90% under 0.182ms; 99% under 0.242ms; 99.99% under 0.91ms
@pfreixes
pfreixes / README.md
Created January 7, 2021 22:24
Emcache vs Go for checking ops/sec and latencies of GETs and SETs for a Memcache server

Go using 1 CPU

$ GOMAXPROCS=1 ./stress 
GET Test results
Ops/sec:  100015
P50: 0.000304 seconds
P99: 0.000825 seconds

SET Test results
@pfreixes
pfreixes / script.py
Created March 16, 2020 21:23
Inferncia del numero de infectats
TAXA_DE_MULTIPLICACIO = 3
PERCENTATGE_DE_HOSPITALITZATS = 20
casos_reportats = [18, 28, 32, 45, 48, 77, 100, 124, 181, 319, 509, 715, 903, 1394]
casos_reals = casos_reportats[0]
for i in range(1, len(casos_reportats)):
casos_reals += ((casos_reportats[i] - casos_reportats[i-1]) * 100 / PERCENTATGE_DE_HOSPITALITZATS) * TAXA_DE_MULTIPLICACIO
print(casos_reals)
import asyncio
import grpc
from grpc.experimental import aio
from proto import echo_pb2
from proto import echo_pb2_grpc
async def run_sync_request(loop):
@pfreixes
pfreixes / test.py
Created December 12, 2019 12:01
Compare performance conditionals between if None and if []
import time
N = 1000000
def benchmark():
l = None
start = time.time()
for i in range(N):
if l:
pass
@pfreixes
pfreixes / test_client.py
Last active May 3, 2019 15:26
Test experimental gRPC using Native Asyncio
import asyncio
import pytest
import subprocess
import time
from grpc_asyncio import grpc_init_asyncio
from grpc_asyncio import create_channel
from tests.acceptance.fixtures import echo_pb2
$ python
Python 3.7.2 (default, Jan 13 2019, 12:51:54)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> f = [1, 2, 3]
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'f']
>>> for x in f:
@pfreixes
pfreixes / address_book.proto
Last active July 18, 2018 21:00
Comparing Proto vs JSON with Python
syntax = "proto2";
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {