Daniel-Journey Weekly Dose -2012/2/26
Algorithm
Algorithm of the Week: Insertion Sort
LINUX
ulimit用于shell启动进程所占用的资源
cat /proc/<tomcat pid>/limits
How do I Find Out Linux CPU Utilization?
sar -u 2 5Report CPU utilization. The following values are displayed:
- %user: Percentage of CPU utilization that occurred while executing at the user level (application).
- %nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority.
- %system: Percentage of CPU utilization that occurred while executing at the system level (kernel).
- %iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
- %idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
Programming
QPS每秒查询率(Query Per Second)
每秒查询率QPS是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准,在因特网上,作为域名系统服务器的机器的性能经常用每秒查询率来衡量。
对应fetches/sec,即每秒的响应请求数,也即是最大吞吐能力。
You can determine whether context switching is excessive by comparing it with the value of Processor\% Privileged Time. If this counter is at 40 percent or more and the context-switching rate is high, then you can investigate the cause for high rates of context switches.
轻量级锁
偏向锁
1.进入内核模式;
2.将CPU的寄存器保存到当前正在执行的线程的内核对象中。
注明:X86架构下CPU寄存器占了大约700字节(Byte)的空间,X64架构下CPU寄存器大约占了1024(Byte)的空间,IA64架构下CPU寄存器占了大约2500Byte的空间。
3.需要一个自旋锁(spin lock),确定下一次调度那一个线程,然后再释放该自旋锁。
如果下一次调度的线程属于同一个进程,哪么此处开销更大,因为OS必须先切换虚拟地址空间。
4.把即将要运行的线程的内核对象的地址加载到CPU寄存器中。
5.退出内核模式。
There are three principles of package cohesion
- (REP) The ReuseReleaseEquivalencePrinciple
- (CCP) The CommonClosurePrinciple
- (CRP) The CommonReusePrinciple
There are three principles of package coupling
- (ADP) The AcyclicDependenciesPrinciple
- (SDP) The StableDependenciesPrinciple
- (SAP) The StableAbstractionsPrinciple
Java
Java轻量级锁原理详解(Lcightweight Locking)
Java轻量级锁原理详解(Lightweight Locking)
Java 语言中的 volatile 变量可以被看作是一种 “程度较轻的
synchronized”;与synchronized块相比,volatile 变量所需的编码较少,并且运行时开销也较少,但是它所能实现的功能也仅是synchronized的一部分锁提供了两种主要特性:互斥(mutual exclusion) 和可见性(visibility)。
Volatile 变量具有
synchronized的可见性特性,但是不具备原子特性。这就是说线程能够自动发现 volatile 变量的最新值。Volatile 变量可用于提供线程安全,但是只能应用于非常有限的一组用例:多个变量之间或者某个变量的当前值与修改后值之间没有约束。因此,单独使用 volatile 还不足以实现计数器、互斥锁或任何具有与多个变量相关的不变式(Invariants)的类(例如 “start <=end”)。 c
Java生成UUID
String s = UUID.randomUUID().toString()
Guidelines for Java Testable Design
Avoid complex private methods
Avoid final methods
Avoid static methods
Use “new” with care
Avoid logic in constructors
Avoid the Singleton
Favor composition over inheritance
Wrap external libraries
Avoid service lookups
1. Use new keyword and call to constructor
2.Use public static factory methods
3.getInstance()
4.Reflective methods for creating instances of classes :
5.Objects creation using Deserialisation :
6.Using Clone method to copy / clone objects of an exisiting object
Architecture


