Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

阅读全文

ucore源码分析:bootloader

1 总述

bootloader的程序存放在硬盘的第一个扇区(512B)。BIOS程序会将bootloader加载到内存0x7c00处,并跳转到这里执行。

阅读全文

基于SDN的简单load balancer

起因

最近在看一个SDN相关的课程,链接:http://www.csg.ethz.ch/education/lectures/ATCN/hs2014
虽然只能看课件,但感觉讲的很不错。课程还附带了几个课后任务,任务说明很详细,可以跟着一步一步做。其中一个就是基于POX控制器写一个简单的load balancer的控制程序。本文主要记录整个实验过程以及一些想法。

阅读全文

git使用

fcbf32f42c9be5416954934b5b091.png

阅读全文

python监控网卡流量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import time
import threading
import signal
from datetime import datetime
last_in_bytes = None
last_out_bytes = None
def curr_traffic(inf):
global last_in_bytes, last_out_bytes
in_traffic, out_traffic = None, None
with open('/proc/net/dev') as f:
lines = f.readlines()
for line in lines[2:]:
line = line.strip()
if line.startswith(inf + ':'):
items = line.strip().split(':')[1].split()
in_bytes, out_bytes = int(items[0]), int(items[8])
if last_in_bytes:
in_traffic, out_traffic = in_bytes - last_in_bytes, out_bytes - last_out_bytes
last_in_bytes, last_out_bytes = in_bytes, out_bytes
return in_traffic, out_traffic
next_thread = None
exit_flag = False
def thread_job(f_handler, inf='eth0', interval=2):
global next_thread, exit_flag
time.sleep(interval)
if not exit_flag:
next_thread = threading.Thread(target=thread_job, args=(f_handler, inf, interval))
next_thread.start()
else:
next_thread = None
time_stamp = int(time.time())
in_traffic, out_traffic = curr_traffic(inf)
print in_traffic, out_traffic
if in_traffic is not None and out_traffic is not None and not f_handler.closed:
f_handler.write('%d, %d, %d\n' % (time_stamp, in_traffic, out_traffic))
def exit_func(signum, stack):
global exit_flag
exit_flag = True
print("Exiting ...")
cnt = 0
while not next_thread and cnt < 3:
time.sleep(1)
cnt += 1
if cnt >= 3:
next_thread.exit()
def output_traffics(outfile, inf='eth0', interval=1):
with open(outfile, 'w') as f:
f.write('time, in_rate(B/s), out_rate(B/s)\n')
thread_job(f, inf, interval)
while not exit_flag:
time.sleep(1)
if __name__ == '__main__':
signal.signal(signal.SIGINT, exit_func)
signal.signal(signal.SIGINT, exit_func)
args = {
'outfile': time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())) + '.csv',
'inf': 'eth0',
'interval': 1
}
output_traffics(**args)

阅读全文

[LeetCode]Median of Two Sorted Arrays

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

阅读全文

[译]管理堆空间:使用JVMTI循环类实例

好久没更新了,把为伯乐在线、Importnew翻译的一篇文章发上来吧。

原文:http://www.javacodegeeks.com/2014/12/own-your-heap-iterate-class-instances-with-jvmti.html

阅读全文

社区划分-Laplace矩阵与谱划分算法

社区划分

实际的网络可能有若干个社区组成,社区内部的节点之间连接紧密,但社区之间的连接却比较稀疏。如下图所示,相同颜色的节点连接紧密,不同颜色的节点连接稀疏。同一种颜色的节点可以划分到同一个分区中。

阅读全文

ServiceLoader的使用

ServiceLoader是Java SE 6所提供的API,用于自动实例化继承了给定接口(或抽象类)的类,类似于Spring依赖注入的功能。

根据其官方文档,对于ServiceLoader来说,有两个概念需要弄清楚:

  • service:指已定义好的接口或者抽象类

阅读全文

Floodlight源码分析(1)

基本概念

在详细分析模块加载过程之前,先了解几个核心概念。

1.模块(Module)

Module是指继承了IFloodlightModule接口的类。IFloodlightModule定义如下:

阅读全文