Tuesday 31 December 2013

AWS Auto Scaling

### System environment settings ###

In Your bashrc: 
export AWS_AUTO_SCALING_HOME=/data/aws-keys/as
export AWS_CREDENTIAL_FILE=/data/aws-keys/as/credential-file-path.template

I believe you already have JAVA_HOME :)

And for AutoScaling cmd API location:
http://ec2-downloads.s3.amazonaws.com/AutoScaling-2011-01-01.zip

You can also go to the following link to get the above command location:
http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/UsingTheCommandLineTools.html#setting-up-your-tools

Go to above link, and select Auto Scaling Command Line Tools To get the following location.

http://aws.amazon.com/developertools/2535?_encoding=UTF8&jiveRedirect=1


#### Starting Auto scalling sample ####

amit@amitAsus:~$ as-create-launch-config MyCmdASLaunchConfig --image-id <Your ami> --instance-type m1.small
OK-Created launch config

amit@amitAsus:~$ as-describe-launch-configs 
LAUNCH-CONFIG  MyCmdASLaunchConfig  <Your ami>  m1.small


NOTE: Do not forget to provide at-least the security group and the key information.

amit@amitAsus:~$ as-create-auto-scaling-group MyCmdASGroup --launch-configuration MyCmdASLaunchConfig --availability-zones us-east-1e --min-size 1 --max-size 2 --desired-capacity 1
OK-Created AutoScalingGroup

amit@amitAsus:~$ as-describe-auto-scaling-groups

AUTO-SCALING-GROUP  MyCmdASGroup  MyCmdASLaunchConfig  us-east-1e  1  2  1  Default
INSTANCE  i-b94ac699  us-east-1e  InService  Healthy  MyCmdASLaunchConfig

amit@amitAsus:~$ as-describe-auto-scaling-groups --headers

AUTO-SCALING-GROUP  GROUP-NAME    LAUNCH-CONFIG        AVAILABILITY-ZONES  MIN-SIZE  MAX-SIZE  DESIRED-CAPACITY  TERMINATION-POLICIES
AUTO-SCALING-GROUP  MyCmdASGroup  MyCmdASLaunchConfig  us-east-1e          1         2         1                 Default             
INSTANCE  INSTANCE-ID  AVAILABILITY-ZONE  STATE      STATUS   LAUNCH-CONFIG
INSTANCE  i-b94ac699   us-east-1e         InService  Healthy  MyCmdASLaunchConfig

amit@amitAsus:~$ as-describe-auto-scaling-instances 

INSTANCE  i-b94ac699  MyCmdASGroup  us-east-1e  InService  HEALTHY  MyCmdASLaunchConfig


######## For deleting #######


If you have not updated the Auto-scaling-group to have min 0 then you will get the following error:
amit@amitAsus:~$ as-delete-auto-scaling-group MyCmdASGroup
    
    Are you sure you want to delete this AutoScalingGroup? [Ny]y
as-delete-auto-scaling-group:  Malformed input-You cannot delete an AutoScalingGroup while there are instances
 or pending Spot instance request(s) still in the group.
Usage:
as-delete-auto-scaling-group
        AutoScalingGroupName [--force-delete  ]  [General Options]
For more information and a full list of options, run "as-delete-auto-scaling-group --help"


IMP: NOTE: If the user wants to terminate all the instances, first update the Auto Scaling group with the following command: [ To have min-size '0' ]

amit@amitAsus:~$ as-update-auto-scaling-group MyCmdASGroup --min-size 0
OK-Updated AutoScalingGroup


amit@amitAsus:~$ as-describe-auto-scaling-groups 
AUTO-SCALING-GROUP  MyCmdASGroup  MyCmdASLaunchConfig  us-east-1e  0  2  1  Default
INSTANCE  i-b94ac699  us-east-1e  InService  Healthy  MyCmdASLaunchConfig
amit@amitAsus:~$ as-describe-auto-scaling-groups --headers
AUTO-SCALING-GROUP  GROUP-NAME    LAUNCH-CONFIG        AVAILABILITY-ZONES  MIN-SIZE  MAX-SIZE  DESIRED-CAPACITY  TERMINATION-POLICIES
AUTO-SCALING-GROUP  MyCmdASGroup  MyCmdASLaunchConfig  us-east-1e          0         2         1                 Default             
INSTANCE  INSTANCE-ID  AVAILABILITY-ZONE  STATE      STATUS   LAUNCH-CONFIG
INSTANCE  i-b94ac699   us-east-1e         InService  Healthy  MyCmdASLaunchConfig

# Now terminate the instance in auto-scaling-group:

INPUT EXAMPLES


    Terminates instance 'i-1' and decrements group size.

    $PROMPT> as-terminate-instance-in-auto-scaling-group i-1 --decrement-desired-capacity     
Terminates instance 'i-2' but does not decrement the group size.
    $PROMPT> as-terminate-instance-in-auto-scaling-group i-2 --no-decrement-desired-capacity     

amit@amitAsus:~$ as-terminate-instance-in-auto-scaling-group i-b94ac699 --decrement-desired-capacity
    
    Are you sure you want to terminate this instance?  [Ny]y
INSTANCE  2d7fc3b8-e725-4b4e-b433-9364f5e6fabe  InProgress  At 2013-12-31T18:48:53Z instance i-b94ac699 was taken out of service in response to a user request, shrinking the capacity from 1 to 0.

# Now you can delete the auto-scaling group:

amit@amitAsus:~$ as-delete-auto-scaling-group MyCmdASGroup
    
    Are you sure you want to delete this AutoScalingGroup? [Ny]y
OK-Deleted AutoScalingGroup
amit@amitAsus:~$ as-describe-auto-scaling-groups 
AUTO-SCALING-GROUP  MyCmdASGroup  MyCmdASLaunchConfig  us-east-1e  0  0  0  Default

amit@amitAsus:~$ as-describe-auto-scaling-instances 
No instances found

amit@amitAsus:~$ as-describe-auto-scaling-groups 
No AutoScalingGroups found

amit@amitAsus:~$ as-describe-launch-configs 

LAUNCH-CONFIG  MyCmdASLaunchConfig  ami-f5381c9c  m1.small

amit@amitAsus:~$ as-delete-launch-config MyCmdASLaunchConfig
    
    Are you sure you want to delete this launch configuration? [Ny]y
OK-Deleted launch configuration


amit@amitAsus:~$ as-describe-launch-configs 
No launch configurations found

NOTE: On Scripting, you might need to wait for some time after issuing few commands because, it takes some time, to give you rest of the information of do a recheck of the expected command out-out.
Few Ref Link:
http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/WhatIsAutoScaling.html
http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/US_BasicSetup.html
http://www.newvem.com/how-to-create-update-and-delete-an-aws-auto-scaling-group/

Monday 30 December 2013

ApacheHttpServers-server-status

ApacheHttpServers-server-status


Apache's http server's 'server-status' page help us a lot to dig more information about that http server.

At Ubuntu you can find this module at:

/etc/apache2/mods-available$ ls -l status*
-rw-r--r-- 1 root root 753 Feb  7  2012 status.conf
-rw-r--r-- 1 root root  64 Feb  7  2012 status.load

And you have to enable the same, type the following. 
[ NOTE: If you see this file under '/etc/apache2/mods-enabled' then no need to type the following command. ]

sudo /usr/sbin/a2enmod status

Then create a 'VirtualHost' to access the 'server-status' page:

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost
</Location>

# You can do allow from the trusted network. 


After configuring, restart the http server.

then: Type the following at your web browser:

http://<YourWebServer>/server-status

Now, you will find the details about your web server.


#######

Current Time: Monday, 30-Dec-2013 12:53:56 UTC
Restart Time: Monday, 30-Dec-2013 11:32:37 UTC
Parent Server Generation: 0
Server uptime: 1 hour 21 minutes 18 seconds
Total accesses: 62355 - Total Traffic: 95.6 MB
CPU Usage: u2091.74 s878.35 cu0 cs0 - 60.9% CPU load
12.8 requests/sec - 20.1 kB/second - 1606 B/request
1 requests currently being processed, 29 idle workers


Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process

Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request



Srv Child Server number - generation
PID OS process ID
Acc Number of accesses this connection / this child / this slot
M Mode of operation
CPU CPU usage, number of seconds
SS Seconds since beginning of most recent request
Req Milliseconds required to process most recent request
Conn Kilobytes transferred this connection
Child Megabytes transferred this child
Slot Total megabytes transferred this slot



SSL/TLS Session Cache Status:
cache type: SHMCB, shared memory: 512000 bytes, current sessions: 0
subcaches: 32, indexes per subcache: 133
index usage: 0%, cache usage: 0%
total sessions stored since starting: 0
total sessions expired since starting: 0
total (pre-expiry) sessions scrolled out of the cache: 0
total retrieves since starting: 0 hit, 0 miss
total removes since starting: 0 hit, 0 miss


#########



Ref Sites:

http://httpd.apache.org/docs/2.0/mod/mod_status.html

http://articles.slicehost.com/2010/3/26/enabling-and-using-apache-s-mod_status-on-ubuntu


Friday 20 December 2013

Monitoring java process

Few notes on how to monitor the java application:

Following is one of the command, using this we can get some information on java status.


$ jstat --help

invalid argument count
Usage: jstat -help|-options
       jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Definitions:

  <option>      An option reported by the -options option
  <vmid>        Virtual Machine Identifier. A vmid takes the following form:
                     <lvmid>[@<hostname>[:<port>]]
                Where <lvmid> is the local vm identifier for the target
                Java virtual machine, typically a process id; <hostname> is
                the name of the host running the target Java virtual machine;
                and <port> is the port number for the rmiregistry on the
                target host. See the jvmstat documentation for a more complete
                description of the Virtual Machine Identifier.
  <lines>       Number of samples between header lines.
  <interval>    Sampling interval. The following forms are allowed:
                    <n>["ms"|"s"]
                Where <n> is an integer and the suffix specifies the units as 
                milliseconds("ms") or seconds("s"). The default units are "ms".
  <count>       Number of samples to take before terminating.
  -J<flag>      Pass <flag> directly to the runtime system.


Following is the example: jstat -<option> <pid-of-java-process> <mili-sec-interval> <NumberOfTime>


NOTE: How you will file the pid of some java process. [ e.g: ps -ef | grep java ] of [ jps ]

Once you get the pid of the java process, you can use the following command. E.g: 21253 is one PID of one of the java service.

$ jps

21253 jar
3089 Jps

$ jstat -gc 21253 250 7

 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT   
3264.0 3264.0  0.0    0.0   26240.0   5706.0   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   5706.0   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   5706.0   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   5706.0   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   5706.0   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   5706.0   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   5706.0   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926


$ jstat -gc `jps | grep -i jar | awk '{print $1}'` 250 7


[ NOTE: This above command is picking the pid of java jar as an param of the command ]


 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT   

3264.0 3264.0  0.0    0.0   26240.0   6363.5   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   6363.5   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   6363.5   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   6363.5   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   6363.5   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   6363.5   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926
3264.0 3264.0  0.0    0.0   26240.0   6363.5   735232.0   10732.7   23068.0 13769.4     21    0.099  192    15.827   15.926


$ jstat -options

-class
-compiler
-gc
-gccapacity
-gccause
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcpermcapacity
-gcutil

-printcompilation


$ jstat -gccapacity `jps | grep -i jar | awk '{print $1}'` 250 7
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC      PGCMN    PGCMX     PGC       PC     YGC    FGC 
 32768.0  32768.0  32768.0 3264.0 3264.0  26240.0   735232.0   735232.0   735232.0   735232.0  12288.0  65536.0  23068.0  23068.0     21   192
 32768.0  32768.0  32768.0 3264.0 3264.0  26240.0   735232.0   735232.0   735232.0   735232.0  12288.0  65536.0  23068.0  23068.0     21   192
 32768.0  32768.0  32768.0 3264.0 3264.0  26240.0   735232.0   735232.0   735232.0   735232.0  12288.0  65536.0  23068.0  23068.0     21   192
 32768.0  32768.0  32768.0 3264.0 3264.0  26240.0   735232.0   735232.0   735232.0   735232.0  12288.0  65536.0  23068.0  23068.0     21   192
 32768.0  32768.0  32768.0 3264.0 3264.0  26240.0   735232.0   735232.0   735232.0   735232.0  12288.0  65536.0  23068.0  23068.0     21   192
 32768.0  32768.0  32768.0 3264.0 3264.0  26240.0   735232.0   735232.0   735232.0   735232.0  12288.0  65536.0  23068.0  23068.0     21   192

 32768.0  32768.0  32768.0 3264.0 3264.0  26240.0   735232.0   735232.0   735232.0   735232.0  12288.0  65536.0  23068.0  23068.0     21   192



jmap

Usage:
    jmap [option] <pid>
        (to connect to running process)
    jmap [option] <executable <core>
        (to connect to a core file)
    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:

    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -permstat            to print permanent generation statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message

    -J<flag>             to pass <flag> directly to the runtime system


jps

4919 SecondaryNameNode
4375 NameNode
4668 DataNode
5237 Jps


sudo jmap -heap 4668

Attaching to process ID 4668, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.7-b01

using thread-local object allocation.

Parallel GC with 8 thread(s)

Heap Configuration:

   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 1048576000 (1000.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 174063616 (166.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:

PS Young Generation
Eden Space:
   capacity = 32374784 (30.875MB)
   used     = 21415272 (20.423194885253906MB)
   free     = 10959512 (10.451805114746094MB)
   66.14799962835274% used
From Space:
   capacity = 5373952 (5.125MB)
   used     = 5365648 (5.1170806884765625MB)
   free     = 8304 (0.0079193115234375MB)
   99.84547684832317% used
To Space:
   capacity = 5373952 (5.125MB)
   used     = 0 (0.0MB)
   free     = 5373952 (5.125MB)
   0.0% used
PS Old Generation
   capacity = 86245376 (82.25MB)
   used     = 363240 (0.34641265869140625MB)
   free     = 85882136 (81.9035873413086MB)
   0.4211704057038374% used
PS Perm Generation
   capacity = 21757952 (20.75MB)
   used     = 16151640 (15.403404235839844MB)
   free     = 5606312 (5.346595764160156MB)
   74.23327342573418% used


6521 interned Strings occupying 519584 bytes.

 sudo jmap -dump:live,format=b,file=heap.bin 4668

4668: Unable to open socket file: target process not responding or HotSpot VM not loaded

The -F option can be used when the target process is not responding

sudo jmap -F -dump:live,format=b,file=heap.bin 4668
Attaching to process ID 4668, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.7-b01
Dumping heap to heap.bin ...
none
null_check
null_assert
range_check
class_check
array_check
intrinsic
bimorphic
unloaded
uninitialized
unreached
unhandled
constraint
div0_check
age
predicate
loop_limit_check
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Heap dump file created

-rw-r--r--  1 root root  11785562 Dec 23 15:30 heap.bin
amit@amitAsus:~$ du -ksh heap.bin 
12M heap.bin

NOTE: I found VisualVM [ GUI tool ] that can be used to read the heap dump. 
 sudo apt-get install visualvm

-------
You should use jmap -heap:format=b <process-id> without any paths. So it creates a *.bin file which you can open with jvisualvm.exe (same path as jmap). It's a great tool to open such dump files.

------
If you use Eclipse as your IDE I would recommend the excellent eclipse plugin memory analyzer

------
Another option is to use JVisualVM, it can read (and create) heap dumps as well, and is shipped with every JDK. You can find it in the bin directory of your JDK.

You can load in visualvm

-----
You can use jhat (Java Heap Analysis Tool) to read the generated file:

======
jhat [ options ] <heap-dump-file>
The jhat command parses a java heap dump file and launches a webserver. jhat enables you to browse heap dumps using your favorite webbrowser.

Note that you should have a hprof binary format output to be able to parse it with jhat. You can use format=b option to generate the dump in this format.

-dump:format=b,file=<filename>

jhat
ERROR: No arguments supplied
Usage:  jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file>

-J<flag>          Pass <flag> directly to the runtime system. For
 example, -J-mx512m to use a maximum heap size of 512MB
-stack false:     Turn off tracking object allocation call stack.
-refs false:      Turn off tracking of references to objects
-port <port>:     Set the port for the HTTP server.  Defaults to 7000
-exclude <file>:  Specify a file that lists data members that should
 be excluded from the reachableFrom query.
-baseline <file>: Specify a baseline object dump.  Objects in
 both heap dumps with the same ID and same class will
 be marked as not being "new".
-debug <int>:     Set debug level.
   0:  No debug output
   1:  Debug hprof file parsing
   2:  Debug hprof file parsing, no server
-version          Report version number
-h|-help          Print this help and exit
<file>            The file to read

For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#<number>" to the file name, i.e. "foo.hprof#3".

All boolean options default to "true"


------------
$ jinfo 
Usage:
    jinfo [option] <pid>
        (to connect to running process)
    jinfo [option] <executable <core>
        (to connect to a core file)
    jinfo [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    -flag <name>         to print the value of the named VM flag
    -flag [+|-]<name>    to enable or disable the named VM flag
    -flag <name>=<value> to set the named VM flag to the given value
    -flags               to print VM flags
    -sysprops            to print Java system properties
    <no option>          to print both of the above
    -h | -help           to print this help message




-----
MAT, jprofiler,jhat are possible options. since jhat comes with jdk, you can easily launch it to do some basic analysis. check this out


-----
sudo apt-get install visualvm 
[sudo] password for amit: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  kde-l10n-engb
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  antlr3 aspectj javahelp2 junit4 libantlr-java libaspectj-java libfelix-framework-java libfelix-main-java
  libgeronimo-jpa-2.0-spec-java libgeronimo-osgi-support-java libhamcrest-java libjna-java libnb-org-openide-modules-java
  libnb-org-openide-util-java libnb-org-openide-util-lookup-java libnb-platform13-java libosgi-compendium-java libosgi-core-java
  libosgi-foundation-ee-java libservlet2.5-java libstringtemplate-java libswing-layout-java
Suggested packages:
  javahelp2-doc libfelix-framework-java-doc libfelix-main-java-doc libgeronimo-jpa-2.0-spec-java-doc
  libgeronimo-osgi-support-java-doc libjna-java-doc libnb-platform13-java-doc libosgi-compendium-java-doc libosgi-core-java-doc
  libosgi-foundation-ee-java-doc libswing-layout-java-doc
The following NEW packages will be installed:
  antlr3 aspectj javahelp2 junit4 libantlr-java libaspectj-java libfelix-framework-java libfelix-main-java
  libgeronimo-jpa-2.0-spec-java libgeronimo-osgi-support-java libhamcrest-java libjna-java libnb-org-openide-modules-java
  libnb-org-openide-util-java libnb-org-openide-util-lookup-java libnb-platform13-java libosgi-compendium-java libosgi-core-java
  libosgi-foundation-ee-java libservlet2.5-java libstringtemplate-java libswing-layout-java visualvm
0 upgraded, 23 newly installed, 0 to remove and 1 not upgraded.
Need to get 26.7 MB of archives.

After this operation, 49.7 MB of additional disk space will be used.

Java memory sizes:

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size

-Xss<size>        set java thread stack size

if you are using Tomcat. Update CATALINA_OPTS environment variable
export CATALINA_OPTS=-Xms16m -Xmx256m;


Few other notes:



Concept of object is language specific: can use JMX for Java

External Links:




http://exchange.nagios.org/directory/Plugins/Java-Applications-and-Servers/check_jmx/details

http://blog.lesc.se/2012/02/how-to-take-java-heap-dump-from-command.html



http://visualvm.java.net/heapdump.html

http://www.rallydev.com/community/engineering/outofmemoryerror-fun-heap-dump-analysis

http://java.dzone.com/articles/java-heap-dump-are-you-task

http://architects.dzone.com/articles/how-analyze-java-thread-dumps

http://www.javaworld.com/article/2072864/heap-dump-and-analysis-with-visualvm.html

https://blog.codecentric.de/en/2011/08/create-and-understand-java-heapdumps-act-4/




Thursday 12 December 2013

understanding inode





understanding inode

 The POSIX standard mandates filesystem behavior that is strongly influenced by traditional UNIX filesystems. Regular files must have the following attributes:


    The size of the file in bytes.
    Device ID (this identifies the device containing the file).
    The User ID of the file's owner.
    The Group ID of the file.
    The file mode which determines the file type and how the file's owner, its group, and others can access the file.
    Additional system and user flags to further protect the file (limit its use and modification).
    Timestamps telling when the inode itself was last modified (ctime, inode change time), the file content last modified (mtime, modification time), and last accessed (atime, access time).
    A link count telling how many hard links point to the inode.
    Pointers to the disk blocks that store the file's contents (see inode pointer structure).

The stat system call retrieves a file's inode number and some of the information in the inode.

Note: it don't carry the filename.

The stat() and lstat() functions take a filename argument. If the file name is a symbolic link, stat() returns attributes of the eventual target of the link, while lstat() returns attributes of the link itself. The fstat() function takes a file descriptor argument instead, and returns attributes of the file that it identifies.


stat MemcachedNetstatCount.py
  File: `MemcachedNetstatCount.py'
  Size: 339       Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d Inode: 590281      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-12-22 11:18:12.000000000 -0500
Modify: 2013-12-21 11:13:37.000000000 -0500
Change: 2013-12-21 11:13:37.000000000 -0500


Referred link:

http://en.wikipedia.org/wiki/Inode
http://en.wikipedia.org/wiki/Stat_%28Unix%29
http://en.wikipedia.org/wiki/System_call
   

making website fast

making website fast

1. Make fewer http request:
 [ image map : spriting ]

2. use CDN: [ pull static contents from there. ]
        and set expary based on the content type.
       
3. expariy header : so cdn will pull after the expary time.

4. gzip content.

5. proxy caching.

6. gzip script and css

7. put the css on the top

8. put the script at the end

9. page fold design

10. DNS lookups [ on the DNS server give a balanced TTL ] [ if you don't switch the server IP the mostly a higher DNS lookup is also good. ]

11. if can be use external iframe call

12. make a page devision of the service. on higher demand request... make sure the you load the service bashed on priority.

13. minify java script code . [ less space... and other related stuffs ]

14. elements/firebug to monitor how much time tacking each service.

[ No mage should be in big format, it should be reduced. ]

15. phase wise image loading also good.

16. avoid redirection

17. remove duplicate script, if any...

18. if possible make ajex cacheable

[ restful api service ]

19. Multiple [alias] sub domain [ so that user can download the content from different subdomain. ]

20. limit download speed.

21. async call.

passwd and shadow file

password and shadow file.

/etc/passwd file:

smithj:x:561:561:Joe Smith:/home/smithj:/bin/bash
Each field in a passwd entry is separated with ":" colon characters, and are as follows:
  • Username, up to 8 characters. Case-sensitive, usually all lowercase
  • An "x" in the password field. Passwords are stored in the ``/etc/shadow'' file.
  • Numeric user id. This is assigned by the ``adduser'' script. Unix uses this field, plus the following group field, to identify which files belong to the user.
  • Numeric group id. Red Hat uses group id's in a fairly unique manner for enhanced file security. Usually the group id will match the user id.
  • Full name of user. I'm not sure what the maximum length for this field is, but try to keep it reasonable (under 30 characters).
  • User's home directory. Usually /home/username (eg. /home/smithj). All user's personal files, web pages, mail forwarding, etc. will be stored here.
  • User's "shell account". Often set to ``/bin/bash'' to provide access to the bash shell (my personal favorite shell).
Perhaps you do not wish to provide shell accounts for your users. You could create a script file called ``/bin/sorrysh'', for example, that would display some kind of error message and log the user off, and then set this script as their default shell.
Note: Note: If the account needs to provide "FTP" transfers to update web pages, etc. then the shell account will need to be set to ``/bin/bash'' -- and then special permissions will need to be set up in the user's home directory to prevent shell logins. See Section 7.1 for details on this.

The ``/etc/shadow'' file contains password and account expiration information for users, and looks like this:
 smithj:Ep6mckrOLChF.:10063:0:99999:7:::
As with the passwd file, each field in the shadow file is also separated with ":" colon characters, and are as follows:
  • Username, up to 8 characters. Case-sensitive, usually all lowercase. A direct match to the username in the /etc/passwd file.
  • Password, 13 character encrypted. A blank entry (eg. ::) indicates a password is not required to log in (usually a bad idea), and a ``*'' entry (eg. :*:) indicates the account has been disabled.
  • The number of days (since January 1, 1970) since the password was last changed.
  • The number of days before password may be changed (0 indicates it may be changed at any time)
  • The number of days after which password must be changed (99999 indicates user can keep his or her password unchanged for many, many years)
  • The number of days to warn user of an expiring password (7 for a full week)
  • The number of days after password expires that account is disabled
  • The number of days since January 1, 1970 that an account has been disabled
  • A reserved field for possible future use


    [ Original link: http://www.tldp.org/LDP/lame/LAME/linux-admin-made-easy/shadow-file-formats.html ]