Month: January 2015

tomcat auto startup script

just save this to /etc/init.d/tomcat and link to /etc/rc5.d/S99tomcat

#!/bin/bash
#
# tomcat        
#
# chkconfig: 
# description: 	Start up the Tomcat servlet engine.

# Source function library.
. /etc/init.d/functions


RETVAL=$?
CATALINA_HOME="/home/tomcat.kingofcoders.com/www/"

case "$1" in
 start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
	    echo $"Starting Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/startup.sh
        fi
	;;
 stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
	    echo $"Stopping Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
        fi
 	;;
 *)
 	echo $"Usage: $0 {start|stop}"
	exit 1
	;;
esac

exit $RETVAL

read count : 315

why i receive zero in my socket

I have two programs, one written in c++, the other is in java. C++ keep sending bytes to java, overtime write out 400KB. Java keep receiving the data using the readBytes function, this function returns an integer which is the number of byte it actually read for the function call. For every send (400kb) in c++ and every read in java, I print out something, so I know c++ is 2 times faster than Java. That mean c++ is sending out the bytes in 2-times speed than java. After 10 seconds, on java side I read out zero from the byte array. But the return value of readBytes() function is still a positive number. Why behave like this? Java should return -1 if no packet or packet lost.

To fix this problem, for every 400kb read from java, I write out the string “end” to c++, c++ have to receive that “end” string before send out another 400kb. So c++ and java are doing handshaking, they align they send speed and write speed, preventing the c++ is sending faster than java. Now, I get all the bytes correctly. So in http, server side and client side *MUST* do handshake. (Correct me if I am wrong)

If the wget is doing handshake to apache server, even in a very slow network, we are very hard to have packet lost. Unless the bandwidth still can’t send out the bytes array in ONE single send() function. But in real case, we usually split the data into very small piece, let say 4KB. So we are very very hard to see packet lost. This explains why I can’t see packet lost/ECN, even I use wget to use up the whole bandwidth.

read count : 223

The jump profiling is little bit enhanced

The jump profiling is little bit enhanced. After load up the ELF kernel, it can read out all symbols and display it in the jump profiling window. It helps people to tracing where the EIP jumping to which c++ function.

jmp profiling with ELF symbol
jmp profiling with ELF symbol

read count : 218