Skip to content

Instantly share code, notes, and snippets.

View zzl0's full-sized avatar

zzl zzl0

View GitHub Profile
@zzl0
zzl0 / hw1.scala
Last active August 29, 2015 13:57
1. 编写一个BankAccount类,加入deposit和withdraw方法,和一个只读的balance属性。
class BankAccount(val balance: Double) {
def deposit(amount: Double): BankAccount = {
require(amount > 0)
new BankAccount(balance + amount)
}
def withdraw(amount: Double): BankAccount = {
require(amount > 0 && amount <= balance)
class memoized(object):
'''Decorator. Caches a function's return value each time it is called.
If called later with the same arguments, the cached value is returned
(not reevaluated).
'''
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
from flask import Flask
from flask import request
app = Flask(__name__)
#Normally this would be an external file like object, but here
#it's inlined
FORM_PAGE = """
<html>
<head>
<title>Flask Form</title>
# coding: utf-8
def get_table_id(tbl_file):
"""
Get table id from .ctb file.
"""
with open(tbl_file, 'rb') as f:
f.seek(-4, 2) # seek to last 4 byte
bytes = f.read(4)
# ==> conf/storage-aggregation.conf <==
[default-aggregation]
pattern = .*
xFilesFactor = 0.6
aggregationMethod = average
# ==> conf/storage-schemas.conf <==
pattern = ^pidl\..*
retentions = 1s:1h,60s:2d,300s:7d,15m:25w,12h:5y
# server.mem.used -> server/mem/used.wsp
xFilesFactor = 0.6
aggregationMethod = average
retentions = 1s:4s,2s:10s
+------------------------+
| |
[('stats.counters.web.*.qps.rate', 16334),
('stats.counters.web.*.bandwidth.rate', 16328),
('stats.counters.web.*.code.504.rate', 3640),
('stats.counters.web.*.code.500.rate', 3630),
('stats.counters.web.*.code.502.rate', 3625),
('stats.counters.web.*.code.503.rate', 3608),
('stats.counters.fusible.*.*.*.fail.rate', 3345)
...
]
1414661115
|
v
+---+---+---+---+---+---+
host=server0,cpu=0->| 8 | | | | | |
+---+---+---+---+---+---+
| | | | | | |
+---+---+---+---+---+---+
| | | | | | |
@zzl0
zzl0 / cpu.py
Created November 21, 2014 06:19
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7775 zhuzhaol 20 0 642m 457m 3800 S 35 0.9 1490:09 twistd
4731 zhuzhaol 20 0 143m 125m 912 S 1 0.3 168:11.27 tmux
4030 zhuzhaol 20 0 620m 15m 3820 S 0 0.0 3:32.29 executor.py
22685 zhuzhaol 20 0 11180 1340 896 R 0 0.0 0:00.14 top
4732 zhuzhaol 20 0 15676 2188 1636 S 0 0.0 0:00.09 bash