Skip to content

Instantly share code, notes, and snippets.

@cgbystrom
cgbystrom / netperf_tcp_crr_reports.markdown
Created May 22, 2011 13:41
Reports for netperf's TCP_CRR test

Reports for netperf's TCP_CRR test (i.e TCP accept() performance)

Below is list of results collected with netperf. The interesting value is TCP_CRR, it measures how fast it can TCP connect/request/response/receive. In short, the transaction rate. The test is used to simulate a normal HTTP/1.0 transaction. What's worrying is that this value has very low on Xen virtualized guests. Performance differences between bare metal and virtualization has been as high as 2-3x.

@cgbystrom
cgbystrom / StringTokenizer.java
Created May 22, 2011 10:28
Super-fast Java string tokenizer
public class StringTokenizer {
public static String[] tokenize(String string, char delimiter) {
String[] temp = new String[(string.length() / 2) + 1];
int wordCount = 0;
int i = 0;
int j = string.indexOf(delimiter);
while( j >= 0) {
temp[wordCount++] = string.substring(i, j);
i = j + 1;
@cgbystrom
cgbystrom / TestArrayIteration.java
Created May 8, 2011 12:51
Compare iteration over native array vs ArrayList (JVM playing tricks on me?)
import java.util.ArrayList;
public class TestArrayIteration {
public static void testArray() {
Integer[] arr = new Integer[1000];
for (int i = 0; i < 1000; i++) {
arr[i] = 1;
}
int total = 0;
@cgbystrom
cgbystrom / node-beaconpush_example.js
Created February 20, 2011 19:17
Quick API overview of node-beaconpush
var bp = require('beaconpush');
// Create a new client
var beaconpush = new bp.Client('<your-api-key>', '<your-secret-key>');
// Get number of users currently connected to your site
beaconpush.usersConnected(function (numConnected) {
console.log('There are ' + numConnected + ' users online');
});
@cgbystrom
cgbystrom / redischat.py
Created December 7, 2010 23:02
Simple Redis chat experiment
# Monkey patching with redis-py didn't work out so well
#from gevent import monkey; monkey.patch_all()
import gevent
import redis
import time
import random
client = redis.Redis(host='localhost', port=6379, db=0)
client.flushdb()
@cgbystrom
cgbystrom / redischat.py
Created December 7, 2010 23:02
Simple Redis chat experiment
# Monkey patching with redis-py didn't work out so well
#from gevent import monkey; monkey.patch_all()
import gevent
import redis
import time
import random
client = redis.Redis(host='localhost', port=6379, db=0)
client.flushdb()
@cgbystrom
cgbystrom / node.js vs Python
Created December 1, 2010 20:56
node.js vs Python with Greenlets
/*
node.js vs Python with Greenlets (say gevent)
I don't get why node.js is being so hyped.
Sure, the idea of writing things in JavaScript both on the client and server-side is really nice.
And JavaScript really fit an event-driven environment with its browser heritage.
But why on earth is boomerang code so appealing to write? I don't get. Am I missing something obvious?
All examples of node.js I see are littered with callbacks yet Ryan Dahl thinks coroutines suck. It doesn't add up for me.
Ludwig Bell - Silvertejp
http://open.spotify.com/track/1yuUvo5DA0QqmKGPPpZlFF
Capo 5
(Ackord relativt capo)
F/C x33210
C x32013
G 11 32301x
G 320013
public function generateUri(protocol:String = "ws"):String {
var uri:String = protocol + "://" + host + "/spheres/" + apiKey + "/users/" + user;
var params:Array = ['authToken=t'];
if (sequenceId > 0) { params.push("sequenceId=" + sequenceId); }
if (channels && channels.length > 0) { params.push("channels=" + channels.join(',')); }
if (params.length > 0) {
uri += "?";
uri += params.join('&');
}
/**
* Small patch by Carl Byström to make the readLine non-greedy.
*
* The MIT License
*
* Copyright (c) 2009 Adam MacBeth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights