Skip to content

Instantly share code, notes, and snippets.

View tsuna's full-sized avatar

Benoit Sigoure tsuna

View GitHub Profile
@tsuna
tsuna / mysql.scala
Created November 7, 2011 10:57
Twitter Querulous leaking connections?
/*
This is for https://github.com/nkallen/querulous/issues/24
I must be doing something wrong but I can't see what. In my loadtests it's pretty apparent
that new MySQL connections are always created all the time and are never re-used, so my app
then runs out of FD.
*/
package whatever
import java.sql.ResultSet
@tsuna
tsuna / count_hbase.sh
Created November 17, 2011 18:42
Script to get stats on the number of KeyValue and size of an HBase table, directly from HFiles
#!/bin/bash
# Copyright (c) 2010, 2011 Benoit Sigoure. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
public static void main(String[] args) throws Exception {
Socket echoSocket = null;
PrintWriter out = null;
String host = null;
int port = 0;
while (true) {
try {
@tsuna
tsuna / server.py
Created January 5, 2012 01:44
A simple example of a threaded TCP server in Python.
#!/usr/bin/python
# A simple example of a threaded TCP server in Python.
#
# Copyright (c) 2012 Benoit Sigoure All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
@tsuna
tsuna / devirt.java
Created February 6, 2012 07:44
Java micro-benchmark on virtual method calls.
import com.google.caliper.SimpleBenchmark;
interface iface {
int foo();
}
class base implements iface {
public int foo() {
return (int) System.nanoTime();
}
@tsuna
tsuna / setbench.java
Created February 9, 2012 18:56
Java integer hash set micro-benchmark
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import com.stumbleupon.mr.HashIntSet; // OpenJDK's HashSet hacked to use built-in `int'
import gnu.trove.set.hash.TIntHashSet;
import com.google.caliper.Param;
import com.google.caliper.SimpleBenchmark;
final class setbench {
@tsuna
tsuna / gist:1865324
Created February 19, 2012 19:33
Output of brew install -v tcptraceroute
==> Downloading http://michael.toren.net/code/tcptraceroute/tcptraceroute-1.5beta7.tar.gz
File already downloaded in /Users/tsuna/Library/Caches/Homebrew
/usr/bin/tar xf /Users/tsuna/Library/Caches/Homebrew/tcptraceroute-1.5beta7.tar.gz
==> ./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/tcptraceroute/1.5beta7 --with-libnet=/usr/local --mandir=/usr/local/Cellar/tcptraceroute/1.5beta7/share/man
./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/tcptraceroute/1.5beta7 --with-libnet=/usr/local --mandir=/usr/local/Cellar/tcptraceroute/1.5beta7/share/man
checking build system type... i686-apple-darwin11.3.0
checking host system type... i686-apple-darwin11.3.0
checking target system type... i686-apple-darwin11.3.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
@tsuna
tsuna / avgkvsz.scala
Created February 29, 2012 07:45
Get average size of a KeyValue from HBase using asynchbase in Scala with the Finagle compatibility layer
import java.util.ArrayList
import scala.collection.JavaConversions._
import com.stumbleupon.async.{Callback, Deferred}
import org.hbase.async.{HBaseClient, KeyValue, Scanner}
import com.twitter.util.{Future, Promise, Return, Throw}
/** Converts a Deferred into a Future. */
implicit def futureFromDeferred[A](d: Deferred[A]): Future[A] = {
val promise = new Promise[A]
@tsuna
tsuna / HBase.scala
Created March 7, 2012 16:59
Atomic increment coalescing for asynchbase
// Copyright (C) 2012 Benoit Sigoure
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,
// see <http://www.gnu.org/licenses/>.
@tsuna
tsuna / mysqlpool.scala
Created March 30, 2012 00:15
MySQL JDBC connection pool for Scala + Finagle
// Copyright (C) 2012 Benoit Sigoure
// Copyright (C) 2012 StumbleUpon, Inc.
// This library is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,