Skip to content

Instantly share code, notes, and snippets.

View almet's full-sized avatar
🗺️

Alexis Métaireau almet

🗺️
View GitHub Profile
@almet
almet / credentials.js
Last active August 29, 2015 14:14
whats-hawk-how-to-use-it
credentials = {
'id': keyMaterial[0:32],
'key': keyMaterial[32:64],
'algorithm': 'sha256'
}
var storage = require('../loop').storage;
var time = require('../loop/utils').time;
storage._client.setex('heartbeat', 3600, time(), function(err) {
console.log("ping result: ", err);
process.exit(0);
});
var storage = require('../loop').storage;
var time = require('../loop/utils').time;
storage.ping(function(err) {
console.log("ping result: ", err);
process.exit(0);
});
@almet
almet / swagger.py
Created February 26, 2015 16:39
Cornice swagger integration.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
def generate_swagger_spec(services, name, base_url, version, **kwargs):
"""Utility to turn cornice web services into a Swagger-readable file.
See https://helloreverb.com/developers/swagger for more information.
"""

Scaling readinglist

There is actually quite a lot to say about what we've learned in the past week or so about scaling the readinglist servers.

Let's start by the begining. When we pushed the first version of the readinglist service in production, it turned out that the performance was pretty bad. We had really slow RPS (requests per second) and the webheads weren't using all the CPU available.

@almet
almet / instructions.rst
Created April 9, 2015 12:34
Loadtest your python app

First, prepare your env:

virtualenv .venv
.venv/bin/pip install pexpect configparser==3.3.0r2 gevent git+git://github.com/mozilla-services/loads.git

Then write your tests and run them:

.venv/bin/loads-runner --config=./config/megabench.ini --user-id=mat --server-url=http://some-server.tld loadtest.TestCase.test_all
print ', '.join(
set([p.contact_email for p in Project.query.all()
if p.get_bills().count() > 10
and (now - p.get_bills().first().date) < datetime.timedelta(weeks=4*6)])
)
var filestorage = require('../loop/index').filestorage;
filestorage.write("key", "value", function(err) {
console.log("write error", err);
filestorage.read("key", function(err, value) {
console.log("read error", err);
console.log("read value", value);
filestorage.remove("key", function(err) {
console.log("delete error", err);
var filestorage = require('../loop/index').filestorage;
filestorage.write("key", "value", function(err) {
console.log("write error", err);
filestorage.read("key", function(err, value) {
console.log("read error", err);
console.log("read value", value);
filestorage.remove("key", function(err) {
console.log("delete error", err);
@almet
almet / session.sh
Created April 16, 2015 12:42
loop server 0.17.4 errors
$ http POST https://loopsvrprod1-l-elb-kzgg495k66v5-783781934.us-west-2.elb.amazonaws.com/v0/rooms @room.json --auth-type=hawk --auth='f7efbb929f7d32db266d1c4d551b89f9de9ae965bd8c26fe8abe9a53eac0747a:' --verify=no --verbose
POST /v0/rooms HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Authorization: Hawk mac="jc7AGxDX07EmkJ/wmk5iRn9FrRfTQS3vcjF1XHq6Uws=", hash="pGGINI02eOeD5Prpog4Cj19Ny+StOW0L6bqwZwk/AYU=", id="f2c0f6fa2e30ddf2d643285fa715326908c1f9e2b726e88230702049bb45246a", ts="1429186386", nonce="IfTKJE"
Connection: keep-alive
Content-Length: 112
Content-Type: application/json
Host: loopsvrprod1-l-elb-kzgg495k66v5-783781934.us-west-2.elb.amazonaws.com
User-Agent: HTTPie/0.9.2