def parentmatched(inputstring)
while inputstring != nil
p inputstring
break if (inputstring.gsub!(/\(\)/, '')==nil)
end
if inputstring.eql?('')
puts "matched"
else
puts "non-matched"
end
end
parentmatched("((())(())()(()))()");
Sunday, February 05, 2012
The Parenthesis Matched?
MAT(Eclipse Memory Analyzer Tool) Usage Simple Check list
Those are some basic steps to do heap dump analysis using MAT when there comes an OOM or memory leak issue:
Pre-condition:Config MAT correctly(you may edit JVM Heap size if it is not sufficient to open a .hprof file, for example, modify "-vmargs-Xmx1280m" to MemoryAnalyzer.ini)
1. Quick Overview on Leak Suspects Report: it will give you some indicator to the leak suspects or the memory issue, it shows the biggest retained heap size after grouping by the same instance name
2. Quick Overview on Overview Pane: it lists the each biggest individual object by retained heap size
3. Open histogram to list number of instances per class, within the histogram, you can check:
--Cheng Chi
Pre-condition:Config MAT correctly(you may edit JVM Heap size if it is not sufficient to open a .hprof file, for example, modify "-vmargs-Xmx1280m" to MemoryAnalyzer.ini)
1. Quick Overview on Leak Suspects Report: it will give you some indicator to the leak suspects or the memory issue, it shows the biggest retained heap size after grouping by the same instance name
2. Quick Overview on Overview Pane: it lists the each biggest individual object by retained heap size
3. Open histogram to list number of instances per class, within the histogram, you can check:
- Order by Shallow heap size
to see if there is a particular object taking too much memory size, then
drill it down by showing its dominator tree view for further analysis
- Order by Retained heap size which
represents the
amount of memory that will be freed by the garbage collector when
this object is collected, then drill it down by showing its dominator
tree view for further analysis
- Order by Objects Count to see if a lot of objects are accumulated, and take the further analysis by viewing the "merge shortest paths to GC roots" (Who is referencing them)
--Cheng Chi
Monday, January 16, 2012
Extend Btrace
If you would like to build you own methods in Btrace, you would prefer to checking out Btrace source code with Netbeans6.9plus and Mercurial, for detail steps, please refer to:
http://netbeans.org/kb/docs/ide/mercurial.html
the Repository URL: https://hg.kenai.com/hg/btrace~hg
Basically, I have added several methods to help monitoring the JVM Performance, for example:
You can take a look at the source code i extend from my github, and extend yours if you like:
https://github.com/joychester/btrace_Ext
http://netbeans.org/kb/docs/ide/mercurial.html
the Repository URL: https://hg.kenai.com/hg/btrace~hg
Basically, I have added several methods to help monitoring the JVM Performance, for example:
- currentProcessCpuTime
- currentProcessCpuUsage
- getTotalCollectionCount
- getGCThroughput
- getMinorGCDetailInfo
- getFullGCDetailInfo
- jstackAllFile(dump all thread stack trace to local file)
You can take a look at the source code i extend from my github, and extend yours if you like:
https://github.com/joychester/btrace_Ext
Tuesday, January 10, 2012
Question about benefits of Web automation
One of my friend asked a question about Automation recently :"is UI test automation actually providing anything useful?"
I Want to share some of thoughts and bias from my own experience and perspective:
The UI automation is a kind of faith. Once you believe it, you need to advocate a lot at first(need dedicate resource and patient from management team), then you get your pay back after a period of time gradually.We should not exaggerate its effect/scope(So do expectation management to the managers are really important and critical). But it really helps in following situations i can think of:1. Prevent the UI regression bugs (Yes, Prevent Regression not Find bugs, due to you need to write workable automation code based on the workable scenario, so once the automation test failed, then you have got a regression bug)2. Reduce the execution time, so as the human resources.(You can run test anywhere, anytime without anyone, and then collect test result and analyze it afterwards) Also it can be scaled easily if you have tons of tests to be run. So the execution time is critical to the projects.3. It is reliable and consistence(Not like Human, Computer always tell the truth :) )4. QA can help with that.It is black box testing, so no need to know the detail implementation of "complex" technique stuff. (seems most of QA person would like to learn and write UI automation tests from my observation)5.Easy to track the history data for Automation test.Automation test result can be kept easily, in which history data can reveal something about quality and people, who always break the build, who always write the bad code and who always write the bad test code, etc.6. Help to do the application health check for QA. Health check is time consuming and always repeatable but not avoidable in some situation, so it is really helpful to do automation in this situation.7.... many more can get from the web i am sure,so i will not mention that to waste of your time, lolFor Practical Way of doing Web UI Automation test, I have done some research about that in my previous days in 2010 although i am not an automation guy... So hope my thoughts can give you some clues to this tough question :)
It is deserved to take a look at the WebDriver project which has been merged to Selenium 2.0 project: http://code.google.com/p/selenium/
In this project, apart from the multiple drivers implementation and clean APIs, the most Important and Essential idea of how to do the Web Automation is introducing the Page Objects Pattern:http://code.google.com/p/selenium/wiki/ PageObjects, which implement the Automation test as a OOD/OOP way. It is much easier to maintain the code and tests than traditional way (which is a record/playback, and step by step describe way to write the automation code).
Anyway, The manual test can be never replaced by Automation test, however, Web UI Automation is also great complement to improve your quality and deserve to put great effort to invest the future. Everything is from the initial purpose, so if Web Automation's strong points can be matched with the project real needs, so just do it with patient and no doubt. If they just want to produce instant results and cut down the bug number on production badly(as i said, Auto test is just preventing bugs not help to find new bugs), then it might loose them confidence i am afraid...
Monday, January 09, 2012
Apache Memory keep increasing due to Rotate logs (with so many Vitural hosts)
We have a lot of Private labels for our application. We managed
their access log and Error log in each Virtual host with Apache Http
server.
If CustomLog or ErrorLog directives are placed
inside a section, all requests or errors for that
virtual host will be logged only to the specified file.This technique is
very useful for a small number of virtual hosts, but if the number of
hosts is very large, it can be complicated to manage. In addition, it
can often create problems with insufficient file descriptors.
We
'luckily' got its limitation recently by adding 2 more private labels
recently. So the Apache memory is keeping increasing gradually even if there is
no any requests coming in.
When using a large number of Virtual Hosts, Apache may run out of available file descriptors (sometimes called file handles)if each Virtual Host specifies different log files.The limit is typically 64, and may usually be
increased up to a large hard-limit.
Solution to our case:
1. We can combine all the Error logs into one Common Error log instead of creating their own within each Virtual host. So it will reduce a lot of file handles at once.
Note: If it does not work for you , then you need have to reduce your number of Virtual Hosts with single box...
Note: If it does not work for you , then you need have to reduce your number of Virtual Hosts with single box...
2. Or you can try to adjust file handles limit before starting Apache, for example 100:
#!/bin/sh
ulimit -S -n 100
exec httpd
Apache official Reference:
It is worthy to take look at the official doc carefully before using its cool features, although it is hard :)
Friday, December 23, 2011
How to Get Garbage Collectors info in Java
There are many GC policy or algorithm you can use in your application, here is a good mapping between JVM configuration and GC collectors:
Note: Thanks for the Reference: http://www.kjkoster.org/zapcat/Zabbix_Java_Template.html
Here is a demo code on how to grab detail GC info of your application
BTW, I have added those capabilities to my customized Btrace source code already :)
Note: Thanks for the Reference: http://www.kjkoster.org/zapcat/Zabbix_Java_Template.html
Here is a demo code on how to grab detail GC info of your application
BTW, I have added those capabilities to my customized Btrace source code already :)
package cputime;
import java.lang.management.*;
import java.util.HashSet;
import java.util.List;
public class GCInfo {
final static HashSet<String> YoungGenGCType = new HashSet<String>();
static{
YoungGenGCType.add("Copy");
YoungGenGCType.add("ParNew");
YoungGenGCType.add("PS Scavenge");
YoungGenGCType.add("G1 Young Generation");
}
final static HashSet<String> OldGenGCType = new HashSet<String>();
static{
OldGenGCType.add("MarkSweepCompact");
OldGenGCType.add("PS MarkSweep");
OldGenGCType.add("ConcurrentMarkSweep");
OldGenGCType.add("G1 Old Generation");
}
public static void main(String[] args) throws InterruptedException{
List<GarbageCollectorMXBean> gcTypes = ManagementFactory.getGarbageCollectorMXBeans();
for (int i=0; i<gcTypes.size();i++){
System.gc();
if(YoungGenGCType.contains(gcTypes.get(i).getName()))
{
System.out.println("Minor GC: " + gcTypes.get(i).getName());
System.out.println("Minor GC Total Count:" + gcTypes.get(i).getCollectionCount());
System.out.println("Minor GC Total Time:" + gcTypes.get(i).getCollectionTime());
}
else{
System.out.println("Full GC: " + gcTypes.get(i).getName());
System.out.println("Full GC Total Count:" + gcTypes.get(i).getCollectionCount());
System.out.println("Full GC Total Time:" + gcTypes.get(i).getCollectionTime());
}
}
}
}
Monday, November 28, 2011
Dealing with "Not enough storage is available to process this command" exception by PsExec
When I am using Btrace to profiling JVM started with JavaServiceWrapper, I got such an annoyed exception:
2> Download PsTools which includes PsExec.exe , and "PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software", or you can download directly from : http://technet.microsoft.com/en-us/sysinternals/bb897553
3> Get your target PID(java.exe) with processExplorer.exe, download from: http://technet.microsoft.com/en-us/sysinternals/bb896653
4> Then Run your command line again using PsExec help:
CMD> C:\btrace\bin>btrace 3272 Test.java
Not enough storage is available to process this command1> Login as a admin user anyway (remotely or locally)
2> Download PsTools which includes PsExec.exe , and "PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software", or you can download directly from : http://technet.microsoft.com/en-us/sysinternals/bb897553
3> Get your target PID(java.exe) with processExplorer.exe, download from: http://technet.microsoft.com/en-us/sysinternals/bb896653
4> Then Run your command line again using PsExec help:
CMD> D:\ProcessExplorer\PsTools>PsExec.exe -s "C:\btrace\bin\btrace.bat" 3272 C:\Test.javaNot only for Btrace, the other external tools can also be run like this way to avoid such a wired Error...
Monday, November 21, 2011
如何计算消息队列中的消息处理时间
求某一时刻进入队列的消息,计算其出队列时间 EL?
定义:
S 为 入队列速率 (根据load的情况,S随不同时间段而变化)
P 为 出队列吞吐量, 通常在给定的系统配置条件下可以认为是常量
TK指K时刻
TN是指对应K时刻进入消息队列的消息出队列所到达的时刻
QD 为初始时刻Queue中剩余的Message的数量
情况1> 假设在一定时间段内,S为定值
当 S 总是<=P时, 在一段时间后任意时刻均无剩余message堆积, 这里暂时不考虑这类问题
当 S > P 时, Queue depth 会不断增长
所以,TN = (S * TK)/P + QD/P
EL= TN-TK
EL = (S * TK)/P + QD/P -TK =(S/P - 1)*Tk + QD/P
EL= TN-TK
EL = (S * TK)/P + QD/P -TK =(S/P - 1)*Tk + QD/P
其中,S,P均为固定值,并且可以被measure
(一般可以通过SQL语句来统计S和P的值, 例如-- select count(*) from dbo.myqueue where ms.timestamp == ctime)
情况2> 假设S为不断变化的正玄函数(斜率即为某时刻的进队速率S‘),则公式可变换为:
EL = (∫ sin(cx)dx) /P + QD/P -TK , 其中积分的范围是0-TK
因此,S需要不断的采样,利用曲线拟合方法(Curve fitting),确定它符合什么样的函数,但不管什么情况,都可以套用类似的模型解决此类问题
Remove the value of the param in URL
It should be formatted your URL when doing aggregation for further analysis, here is Ruby code to be copy with the URL which includes params within it:
string1 = "http://www.google.com.hk/search?sclient=psy-ab&hl=en&newwindow=1&safe=strict&biw=1440&bih=693&noj=1&source=hp&q=wicket+1.5+URL&oq=wicket+1.5+URL&aq=f&aqi=g2&aql=&gs_sm=e&gs_upl=3231l4087l0l4226l4l4l0l0l0l2l302l832l2-2.1l3l0";
if (string1.include? "?")
string1.insert(-1, "&")
string1.gsub!(/=(.*?)&/, "&")
puts string1.chomp!("&")
end
The output result:
http://www.google.com.hk/search?sclient&hl&newwindow&safe&biw&bih&noj&source&q&oq&aq&aqi&aql&gs_sm&gs_upl
Tuesday, November 15, 2011
Essential Counters for Performance Monitoring
The goals of performance monitoring i always think about are:
More counters you add and higher granularity you made will bring more overhead to your system, you should make trade offs on selecting counters and sample interval.There is no silver bullet after all...
- Health indicator: it will show you if the current status of your application farm is in good shape or not; or let you predict the trend;
- Find out the bottleneck of your system from a high level, it is really helpful for Engineers to get start to get issue fixed;
- Help to do trouble shooting: the counters will drive us to the right direction from different angles to find the root cause instead of "smart guess";
- Operation management: Capacity Planning and Risk management, try to resolve any performance or stability issues before it comes!
Counters For OS | Explaination | |
---|---|---|
Server Uptime | elapse time since server recent start up | |
Processor--Total CPU% | the percentage of elapsed time that the processor spends to execute a non-Idle thread. | |
Processor--% User Time | the percentage of elapsed time the processor spends in the user mode. | |
System--Processor Queue Length | the number of threads in the processor queue. There is a single queue for processor time even on computers with multiple processors. Therefore, if a computer has multiple processors, you need to divide this value by the number of processors servicing the workload. A sustained processor queue of less than 10 threads per processor is normally acceptable, dependent of the workload. | |
Memory--% MEM in use | the ratio of Memory\\Committed Bytes to the Memory\\Commit Limit. | |
Memory--pages/sec | the rate at which pages are read from or written to disk to resolve hard page faults. | |
Disk Space--DISK C: | the percentage of Used space on Disk C | |
Disk Space--DISK D: | the percentage of Used space on Disk D | |
Disk Space--DISK E: | the percentage of Used space on Disk E | |
DISK IO --Avg. Disk Queue Length | the average number of both read and write requests that were queued for the selected disk during the sample interval. | |
DISK IO --% Disk Time | the percentage of elapsed time that the selected disk drive was busy servicing read or write requests. | |
DISK IO --Avg. Disk sec/Read | the average time, in seconds, of a read of data from the disk. | |
DISK IO --Avg. Disk sec/Write | the average time, in seconds, of a write of data to the disk. | |
DISK IO --Disk Reads/sec | the rate of read operations on the disk. | |
DISK IO --Disk Writes/sec | the rate of write operations on the disk. | |
NetWork IO--Packets Sent/sec | the rate at which packets are sent on the network interface. | |
NetWork IO--Packets received/sec | the rate at which packets are received on the network interface. | |
TCP--TCP Connections EST | the number of TCP connections for which the current state is either ESTABLISHED or CLOSE-WAIT | |
Total Process cnt | Total number of processes on the server | |
Counters For Specific Process instance | Explaination | |
---|---|---|
Apache Http Server -- Apache Process | ||
Process Uptime | elapse time since apache process recent start up | |
Process CPU% | the percentage of elapsed time that the processor spends on Apache Process. | |
Process Memory in use | Memory usage by apache process | |
Busy workers cnt | the number of threads which are in use for requests | |
Idle workers cnt | the number of threads which are not receiving any request | |
requests/sec | throughput of apache Http server | |
KB/sec | throughput of apache Http server | |
Application Server -- Java Process | ||
Process Uptime | elapse time since java process recent start up | |
Process CPU% | the percentage of elapsed time that the processor spends on java Process. | |
Private Bytes | the current size, in bytes, of memory that this process has allocated that cannot be shared with other processes. | |
Working Set | Working Set is the current size, in bytes, of the Working Set of this process. The Working Set is the set of memory pages touched recently by the threads in the process | |
Used Heap Size | JVM Heap size is in use currently | |
Live Threads cnt | The number of threads currently active in this process | |
Accumulate GCTime | the total time taken by GC activities | |
Async Server--JMS MQ Process | ||
Process Uptime | elapse time since JMS process recent start up | |
Process CPU% | the percentage of elapsed time that the processor spends on JMS Process. | |
Private Bytes | the current size, in bytes, of memory that this process has allocated that cannot be shared with other processes. | |
Working Set | Working Set is the current size, in bytes, of the Working Set of this process. The Working Set is the set of memory pages touched recently by the threads in the process | |
Message Queue Depth | the current number of messages that are waiting on the queue | |
DLQ cnt | the current number of messages which in Dead Letter Queue | |
Live Threads cnt | The number of threads currently active in this process | |
DB Connections cnt | the current number of open database connections used by this process | |
DB Server -- SQL Server Process | ||
Process Uptime | elapse time since SQL Server process recent start up | |
Process CPU% | the percentage of elapsed time that the processor spends on SQL Server Process. | |
Process Memory in use | Memory usage by SQL Server process | |
Free Space in Temp DB | Tracks free space in tempdb in kilobytes | |
User Connections | the current number of connections (and users) are using the server | |
Buffer Cache Hit Ratio | indicates how often SQL Server goes to the buffer, not the hard disk, to get data. Had better larger than 90% | |
Full Scans/Sec | the number of unrestricted full scans during unit time. These can either be base table or full index scans. | |
Transactions/Sec | The number of transactions started for the database during unit time | |
Average Wait Time | the average amount of wait time (milliseconds) for each lock request that resulted in a wait |
More counters you add and higher granularity you made will bring more overhead to your system, you should make trade offs on selecting counters and sample interval.There is no silver bullet after all...
Subscribe to:
Posts (Atom)