Skip to main content

Posts

Showing posts from December, 2013

Understanding Memory Usage

Working Set  is the set of actively used pages. A process needs that amount of physical memory to run properly. If there is not enough physical memory, process will spent considerable amount of time to swapping. Thus performance will be degraded. If this problem is system wide, all process are hungry for physical memory, system will spent most of time to swapping witout any actual work. This is called  thrasing . Linux top Command for Process Memory Usage Column explanations from  Understanding Process memory : ·           RES  shows the actual physical RAM used by your process. ·           VIRT  shows the actual virtual memory reserved by your process. ·           DATA  shows the amount of virtual private anonymous memory reserved by your process. That memory may or may not be mapped to physical RAM. It corresponds to the amount of memory intended to store process specific data (not shared). ·           SHR  shows the subset of resident memory that is file-backed

Virtual Memory

Introduction In simple and straightforward terms: Modern Operating Systems (OS) controls access to memory. Process demands memory and OS provides. Each process thinks it has a large consecutive space of memory which is called  virtual memory .  For a 32 bit system virtual address space is 4G wide. For a  64 bit system virtual address space size is 256TB . Virtual memory brings some very important advantages. Each process can address whole address space available; however, system may not have that much physical memory. Each process has its own private virtual memory space which other process cannot access. Virtual memory concept also lets operating system map files. Finally virtual memory concept sharing similar memory areas between processes. Paging Virtual address space is divided into small fixed size consecutive address blocks which are called  pages . Usually a page is 4 kilobytes in size. Similarly physical address space is divided into such blocks which are called fram

Java Application as Linux Service

Introduction Configuring a java application as a Linux service, makes management of application easier.   Steps 1.         Create  following   init.d  script under / etc / init.d  directory. Suppose its name is service_name.sh. #!/bin/bash # # source function library . /etc/init.d/functions RETVAL=0 EXECUTABLE="path_to_java_executable" WORKDIR="service_working_directory" LAUNCH_OPTIONS="application_launch_parameters" GREP_EXPR="%application_name%" PIDFILE="%application_name%.pid" start() { echo -n $"Starting %application_name% service: " cd $WORKDIR if [[ -f $PIDFILE ]];then echo "pidfile is already existing. Cancelling service start." return fi nohup ${EXECUTABLE} ${LAUNCH_OPTIONS} & RETVAL=$? pid=$(ps -ef | grep ${GREP_EXPR} | grep -v grep| grep -v service | grep -v init.d | awk '{print $2}') echo $pid > $PIDFILE

Processing of last_update_date tracked rows

Introduction Suppose it is necessary to process rows according to last_update_date using an external application. For example there might be two systems that needs to be synchronized which should be achieved through a middleware application. Requirement roughly can be described such that when last_update_date of a row changes, in other words a row is updated or a new row is added, it is necessary to take some actions, e.g. synchronize peer system. Considering life cycle of external application, it is necessary to differentiate two phases: early phase and late phase. Early phase  is the phase when external application is first launched. Existing data must be processed. After all existing data is processed, early phase ends. Since all pre-existing data is processed, early phase is probably the phase which most processing throughput happens. Late phase  is the phase new updates are processed.  Late phase spans the external application lifecycle excluding early phase.  

Creational Patterns : Singleton

Properties: -            Ensures that only one instance is created. -            Global access is provided to single instance. -            Conventionally has a  public static  method named  getInstance/getXYZ  ,where XYZ stands for class name, to return the class instance. -            Suitable for creating factory instances and system wide unique resources. Implementation: -            Constructor should be made  private/protected  to prevent arbitrary instance creation. -            Single instance is created and assigned to a  public static  member of the class. This class member is conventionally named as  instance . -            Class instance is exposed to outside world by a  public static  method named  getInstance/getXYZ  ,where XYZ stands for class name. Java Standard Library Implementations: -            java.lang.Runtime -            java.awt.Desktop -            java.awt.print.PrinterJob Example Usage: PrinterJob pj  =  Print

Creational Patterns : Simple Factory

Properties: -            Hides details of class instance creation and actual class implementation. This allows easy replacement of class implementation and gives flexibility to change the way new instance construction  is done. -            Creates and  abstraction  layer between client code and object needs to be created, thus facilitates  loose coupling . -            Client provides attributes of the object it needs to create and defers instantion to factory. It is not obligatory to supply any attributes though. -            Factory creates a suitable class instance according to attributes supplied.  -            The problem with Factory pattern is when a new implementation is added Factory class needs to be modified which vilotaes the open-closed* principle. [*] http://en.wikipedia.org/wiki/Open/closed_principle Implementation: -            Factory class has method named  createXYZ  which takes necessary arguments. -            createXYZ  method cre

Behavioral Patterns : Visitor

Properties: -            Used when it is necessary to execute actions on members of an object structure (e.g. collections, hierarchical structures, composite structures). -            Separates algorithm of the actions from the object structure members. So that new algorithms can be modified easily. -            This pattern relies on polymorphic calls and helps to follow  open/closed principle . -            Another advantage is that visitor objects may be statefull. -            One disadvantages is, while it is easy to add new visitors, it is difficult to add new observable objects. Implementation: -            Visitor  interface declares visit methods. For each  ConcreteVisitable object a separate overridden visit method should be declared. -            ConcreteVisitor  implements visitor. -            Visitable  interface declares the accept method to which visitor instance is passed. -            ConcreteVisitable  implements visitable interface and d