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 / a.rst
Last active March 8, 2016 16:01
Optimization is not free, it just cost space

Output of this command [1]

$ python set_memmory_usage.py
1. Differnece between list, dict and set containers with 1M of numbers regarding the size and container overhead
Sizeof with dict type: 48M, overhead per item 50b
Sizeof with set type: 32M, overhead per item 33b
Sizeof with list type: 8M, overhead per item 8b
----------
@pfreixes
pfreixes / animations.py
Last active January 18, 2016 18:45
Animations with Python and terminal output
# More info about ANSI escape sequences
# http://ascii-table.com/ansi-escape-sequences.php
import sys
import random
from time import sleep
ROWS = 10
while True:
@pfreixes
pfreixes / gist:4270102430913f16ee87
Created November 17, 2015 11:36
Python is sometimes a bit depresing
+-------------------+-------------------------+---------+---------+---------+-------+
|Name |Parameters | Real| User| Sys| Msg/s|
+-------------------+-------------------------+---------+---------+---------+-------+
|Pika_Threads |{'threads': 2} | 3.03| 1.24| 0.15| 1650|
|Pika_Threads |{'threads': 4} | 1.78| 1.26| 0.19| 2808|
|Pika_Threads |{'threads': 8} | 1.48| 1.12| 0.16| 3378|
|Pika_Threads |{'threads': 16} | 1.43| 1.10| 0.27| 3496|
|Pika_Threads |{'threads': 32} | 1.31| 1.14| 0.30| 3816|
|Pika_Async |{'connections': 2} | 2.75| 0.96| 0.07| 1818|
|Pika_Async |{'connections': 4} | 1.98| 0.88| 0.09| 2525|
@pfreixes
pfreixes / 16K amqp messages per second
Created October 15, 2015 20:21
16K amqp messages per second
1 publisher > 1 queue
queues = 10K
messages per queue = 100
concurrence consumers = 20
queues binded by consumer = 50
qos by consumer = 40
asyncronous pattern
Throughput got 16K messages, why ?
@pfreixes
pfreixes / .md
Last active August 29, 2015 14:25
Looking for the best tradeoff between the amount of operations and the latency to write them.

Size operation arround 50 bytes, write concern is acknowledgment.

Bulk trhoughput vs number of update operations

2 4 8 16 32 64 128 256 512
4.5K 9K 12K 16K 19k 22K 23K 24K 27K
@pfreixes
pfreixes / mongodb_performance_updates.md
Last active August 29, 2015 14:25
Using MongoDB with environments with burst write operations

Leave ready the DB with a set of 10K documents with a length arround of 1K

from pymongo import MongoClient
from bson.objectid import ObjectId

client = MongoClient('localhost', 27017)
db = client['test']
collection = db['test']
collection.remove()
@pfreixes
pfreixes / consumers_trheaded_vs_asyncronous.md
Last active August 29, 2015 14:25
1K pika consumers, asyncronous vs thread

All consumers consuming over 1K queues, growing from 1 to 1K messages.

consumer_threaded_pika.py

import pika
import threading
import sys
import time
@pfreixes
pfreixes / gist:ac9974bde0dcfe500f5a
Created April 4, 2015 17:36
Because the way matters #python and prime numbers
N = 100000
# First approximation, brute force
def is_prime(number):
if number == 2:
return True
for x in range(2, number/2+1):
if number % x == 0:
return False
return True
@pfreixes
pfreixes / gist:e7f6f89f7ef60234b5dc
Created February 20, 2015 17:34
Use memoization to speedup the python version
#!/usr/bin/env python
UPPER_ITERATIONS = 10000000
def fac(n):
if n == 0:
return 1
return n * fac(n - 1)
@pfreixes
pfreixes / gist:25b7f7713ac29f8aefba
Last active August 29, 2015 14:08
Is works because of immutability of integer python implementation
Boolean are integers, integers are immutable and immutable objects are shared along the life cycle of your programm. Then it comes true
>>> False is False
True
>>> 123 is 123
True
>>> [1] is [1]
False