IP Header = 20 TCP Header = 20 Ethernet = 20
Loopback RTT = 0.01 msec Datacenter RTT = 0.250 msec
1 Gbps = 128 MBps Assume 40% overhead, 600 Gps = 75 MBps
| #include <stdlib.h> | |
| #include <stddef.h> | |
| /* | |
| * C struct hack - the last member of the struct is of variable length | |
| * | |
| * C99 however introduces the concept of a flexible array member, which | |
| * allows the size of an array to be omitted if it is the last member | |
| * in a structure | |
| */ |
| # Notes: | |
| # List comprehension (listcomps) is an expression. | |
| # With list comprehension, you get back a list, not a generator. | |
| # With generator expression, you get back an iterator that computes values as an when needed. | |
| # prints [1, 2, 3, 4] | |
| [x for x in (1, 2, 3, 4)] | |
| # prints [2, 4] | |
| [x for x in (1, 2, 3, 4) if x % 2 == 0] |
| def gen(num): | |
| n = 0 | |
| while n < num: | |
| yield n | |
| n += 1 | |
| # returns a generator object | |
| g = gen(3) | |
| # returns 0 |
| items = [1, 2, 3] | |
| it = iter(items) | |
| # prints 1 | |
| print it.next() | |
| # prints 2 | |
| print it.next() | |
| # prints 3 |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns | |
| Compress 1K bytes with Zippy 3,000 ns | |
| Send 2K bytes over 1 Gbps network 20,000 ns | |
| Read 1 MB sequentially from memory 250,000 ns | |
| Round trip within same datacenter 500,000 ns | |
| Disk seek 10,000,000 ns |
| branch = redis_unstable on github.com/twitter/twemproxy | |
| ## redis-benchmark through a local twemproxy (nutcracker) | |
| $ ./redis-benchmark -q -p 22121 | |
| SET: 63291.14 requests per second | |
| GET: 65359.48 requests per second | |
| INCR: 64935.07 requests per second | |
| LPUSH: 67114.09 requests per second | |
| LPOP: 68493.15 requests per second | |
| SADD: 66225.16 requests per second |
IP Header = 20 TCP Header = 20 Ethernet = 20
Loopback RTT = 0.01 msec Datacenter RTT = 0.250 msec
1 Gbps = 128 MBps Assume 40% overhead, 600 Gps = 75 MBps
| // my response to https://groups.google.com/forum/?fromgroups#!searchin/play-framework/cake/play-framework/LQ2y40QNZaE/qvRFw5of-rQJ | |
| import play.api._ | |
| import play.api.mvc._ | |
| // Domain object | |
| case class User(id: String, name: String) | |
| // Trait defining the service component | |
| trait UserServiceComponent { |
| // (1). Simplified - A Thing[A] to compute another Thing[B] | |
| // Thing[A] is like a simplest posssible container for a value and the | |
| // pattern, given a Thing[A], and a function flatMap, pulls a value of | |
| // type A out of the Thing[A] and applies the function flatMap() on this | |
| // value of type A and returns another new Thing[B] with a value of | |
| // type B injected into it by the constructor (apply() method here) | |
| // encapsulates a monad in loose sense | |
| case class Thing[+A](value: A) { | |
| def flatMap[B](f: A => Thing[B]) = f(value) | |
| } |
| // from: http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di | |
| // (1). | |
| case class User(username: String, password: String) | |
| trait UserRepositoryComponent { | |
| val userRepository: UserRepository | |
| class UserRepository { |