Skip to content

Instantly share code, notes, and snippets.

@daggerrz
daggerrz / gist:9310425
Created March 2, 2014 17:41
GraphiteReporter
package com.tapad.common.metrics
import java.net.Socket
import java.io._
import com.tapad.common.log.Logging
import com.twitter.ostrich.stats._
import java.util.TimerTask
object GraphiteReporter {
def apply(prefix: String, host: String, port: Int, reportInterval: Long) = {
val excludedDependencies = Seq(
"org.slf4j" -> "slf4j-log4j12",
"log4j" -> "log4j",
"org.jboss.netty" -> "netty" // We have the io.netty dependency
)
val removeUnwantedDependencies = libraryDependencies ~= { deps =>
deps.map { d =>
excludedDependencies.foldLeft(d) { case (acc, (group, artifact)) => acc.exclude(group, artifact) }
}
@daggerrz
daggerrz / MemoryMappedFile.scala
Created June 11, 2012 21:00
Memory mapping files larger than Integer.MAX_VALUE
import java.io.RandomAccessFile
import java.nio.channels.FileChannel
import org.jboss.netty.buffer.{ByteBufferBackedChannelBuffer, ChannelBuffer, ChannelBuffers}
/**
* Maps a the filename to a memory mapped random access file across 1 or more buffers.
* Support files up to Long.MAX_VALUE.
*
* @param filename the file to map
* @param maxBufferSize the maximum number of bytes to map per buffer
@daggerrz
daggerrz / CircuitBreakingDispatcherSemantics
Created January 24, 2012 15:04
Akka 1.3 circuit breaking dispatcher
package com.tapad.util
import akka.dispatch._
import java.util.concurrent.atomic.{AtomicInteger, AtomicBoolean}
class LogAndDiscardCircuitBreakerPolicy(val maxMailboxSize: Int, loggable: Logging) extends CircuitBreakerPolicy {
def onOverflowStart(mailboxSize: Int) { loggable.log.warn("Mailbox size is above {}. Ignoring messages until size is back below.", maxMailboxSize) }
def onBackToNormal(overflowCount: Int) { loggable.log.info("Mailbox size is back below {}. A total of {} messags were discarded.", maxMailboxSize, overflowCount) }
def replyToOverflow(overflowCount: Int, msg: Any) : Either[Exception, Any] = Left(new IllegalArgumentException("This overflow policy is not configured for request-reply actors."))
@daggerrz
daggerrz / Scripts
Created April 1, 2011 21:58
Diff of Voldemort master and my setup today
For the BDB test:
bin/voldemort-performance-tool.sh --record-count 20000000 --value-size 2048 --ops-count 1000000 --target-throughput 10000 --store-name test -r 70 -m 30 --url tcp://localhost:6666 --interval 5
For the Krati test:
bin/voldemort-performance-tool.sh --record-count 20000000 --value-size 2048 --ops-count 1000000 --target-throughput 10000 --store-name test2 -r 70 -m 30 --url tcp://localhost:6666 --interval 5
@daggerrz
daggerrz / UnfilteredTodoServer.scala
Created December 15, 2010 00:52
SproutCore Todos backend in Unfiltered Scala
package com.todos
import net.liftweb.json.JsonAST._
import net.liftweb.json.JsonDSL._
/**
* Non-persistent Unfiltered implementation of the SproutCore back-end.
* See <a href="http://wiki.sproutcore.com/w/page/12413020/Todos%2006-Building%20the%20Backend">SproutCore docs</a>
*/