Archive for the ‘Uncategorized’ Category

Tracing facilities and tools for Unix

May 28, 2009

I’ve become confused with amount of tools and facilities ending with “trace” which exist on different Unix-like OSes. This small article lists them together will small description

ptrace

A system call of System V and BSD (also exists in Linux) which may be used by one process “to observe and control the execution of another process”. Available commands include reading and writing a memory of the process (used for setting breakpoints), reading CPU registers, intercepting signals sent to the process, intercepting system calls made by the process. Intercepting is done by stopping a traced process and sending a signal SIGCHILD to process which requested the tracing. Observer then may request information about stopped process and may continue its execution.

strace

A Linux utility which is used to trace system calls and signals. Uses ptrace() system call

ktrace/ktruss/kdump

A system call of BSD unixes which traces system calls and signals of specified process and writes the data in specified file. Since there is no context switch between processes, a tracing is faster. Trace data are not human-readable. A ktrace is also a name of command-line utility for unixes of BSD family which does a process tracing by invoking ktrace(). kdump is an utility which reads tracing info written into file by ktrace() and prints this info in human-readable form. ktruss is another command-line utility for BSD-derived unixes which traces system calls and signals for some process by using ktrace() system call. It prints tracing info in human-readable form on console.

systrace

A facility of some BSD unixes which is intended to restrict certain system calls done by some process. In simplest case can be used just to trace those calls. Implemented as pseudo-device “/dev/systrace”. System call ioctl() is used to perform actions such as attaching to process or permit to do a system call. System call read() on systrace device will block until some traced process will perform a system call. Systrace is also a name of command-line utility which uses systrace facility.

ltrace

A command-line utility which traces system calls and calls to functions of dynamically linked libraries. System calls are traced using ptrace(). Library calls are traced by analyzing symbol table of ELF file, calculating addresses and placing breakpoints for every library call using ptrace(). When breakpoint hits a stack trace of the process is obtained (using ptrace()) and compared with breakpoint table to get function name.

dtrace

Tracing facility originally developed for Solaris and later moved to other Unixes. It consists of core, “probe providers” which register with core, and “probe consumers” which are user-level processes like ‘dtrace’ command-line tool. Consumers can express an interest in some probe by asking a core to enable it. Core, in turn, uses provider to obtain and address.

Book review: “Internet multimedia communications using SIP”

July 21, 2008

For a long time my only source of information about SIP was RFC 3261 and others. However, recently we got a new book in a library Book is called “Internet multimedia communications using SIP” by Rogelio Martinez Perea. Now I’ve finished about 90% of the book, so I already have an opinion which I would like to share.

This book is interesting in it’s approach. It tells about lots of things, often oversimplifying them just to show only essential features.

First part is called “Fundamentals”. It explains principles of signaling/media approach, then moves to explanation of TCP/IP protocol family basics. Then on abstract level (without syntax!) it explains functionality of SIP. This part is intended for people who know absolutely nothing about networks.

Second part is called “core protocols”. First it explains basics of SIP syntax and interaction. Then it contains Java practice with free SIP stack. Next it moves to SDP, also with small Java practice. Next it moves to RTP, also with Java practice. And finally, all pieces are assembled together in soft-phone application and proxy application.

For me, such composition of the book is not very good. If somebody needs explanation of TCP/IP principles and never used sockets, then he probably will not be able to troubleshoot an application. On the other hand, advanced people like me will find code too amateurish, and most explanations as oversimplified.

Third part is called “Advanced topics” and tries to cover in small degree many (I’ve found 10) areas of SIP usage. There are no programming here, just concepts. This chapter, in my opinion, is the best in the book.

This book is quite good for students: it contains “main facts” about technology, so person will at least know that is it, and he can get deeper knowledge, if necessary. Other people who can benefit from the book are curious engineers, programmers and managers. I suspect that nobody will actually use practical part of the book.

To prove that I actually read the book and that my opinion has a base, I’m posting here a list of small annoyances, errors and mistakes I’ve found so far. Unfortunately, there are no site or e-mail address where I could send this list, so I’m posting it here in hope that author finds it useful.

  • Figure 6.15 on page 91 has an error. ACK request after 200 OK response always follows the same path as BYE request.
  • In chapter 8.6.7, an Example 4 doesn’t explain at which moment a “Dialog” object was created. There are no code, compared with Example 3, which would create a dialog. I perfectly understand that dialog is created automatically by stack, because default value of property “javax.sip.AUTOMATIC_DIALOG_SUPPORT” is “on”, so dialogs in fact are created in both cases. I believe it is worth mentioning, or replacing with creation of dialog explicitly. I believe that in this case oversimplification is bad.
  • In chapter 12.5.5 author explains that he uses TimerTask to close a dialog in case ACK is not received. Such approach is totally wrong. Actually a timeout for ACK is handled by stack, which will notify SipListener through processTimeout() method. Also, if TimerTask is intended only for ACK timeout, then a task should be cancelled if ACK is received. I believe that TimerTask should be removed at all.
  • In chapter 13.2.1, an exception #4 contains wrong information about CANCEL processing. In fact, proxy doesn’t send “487 terminated” response on INVITE. Such response will be sent by UA. Chapter 13.3.3 contains correct information about processing a CANCEL. I believe that author made this mistake because he wanted to make simpler proxy example.
  • In chapter 13.6.5 author explains proxy example. He uses ArrayList for context storage. A Map should be used instead, because code will be simpler and will work faster.

I hope that author will accept this list as a sign of respect from another professional. I believe that going to the matter is better then empty praise and stupid testimonials.

SIP gets more and more mindshare, and I fill that demand for professionals will grow. That puts me in a good position.

Container approach in Java. Part 2: instances (version 2.0)

June 2, 2008

In a previous article I’ve defined a component/container architecture and explained the reasons why such architecture is used. This article will cover real examples of containers which are known to me. in historical perspective.

Servlet containers

Earliest containers known to me are servlet containers. These are typical IoC containers, used on servers communicating asymmetric request/response protocols, like HTTP. This allows applying IoC approach to handling of protocol logic: servlets must implement “Servlet” interface containing method “service()”. This method is invoked by container for each incoming request. For HTTP, IoC principle also applies to creation and sending of responses. 

Interface “Servlet” also contains methods “init()” and “destroy()”, which are used for lifecycle management. Method “init()” also used for ”context” injection. From this “context” a servlet can extract references to all components it depends on. 

Servlets are developed according to special convention, so they are collections of classes and XML descriptor.

Well-known examples of servlet containers are Apache Tomcat, Jetty, Resin.

EJB containers

EJB spec is also quite old. It is a “generic” component/container architecture for complex data-processing logic used inn enterprize IT systems. Curioulsy enough, it was developed as distributed architecture, meaning that each component will be located on dedicated machine, and container will provide inter-component communication. IoC principle is applied to lifecycle and persistence. Dependencies are resolved using lookup (in JNDI facility), however binding in JNDI is done automatically.

Later EJB spec changed to support “local” access between components. Anyway, it was and still criticised for being complex and slow, and many other frameworks emerged to fix its flaws.

Well-known examples of EJB containers are: Glassfish, Apache OpenEJB, JBoss, JOnAs, Bea WebLogic, IBM websphere, and lots of others.

Microcontainers

Microcontainers are “generic” component containers focusing only on local access and providing just lifecycle and late binding. All other features could be realized ”on top” of container, by implementing them as a components. 

Apache Avalon was first known to me attempt to build “lightweight” container. Later its developers divided, but they have tried to support common framework for containers. This framework follows “interface injection” approach, which means that dependency on something is declared by implementing certain interface, and the same interface is used for injecting this dependency. Thus, Avalon framework contains lots of interfaces, for example for lifecycle, logging, configuration. However, injection is used only for dependencies which are part of framework. For resolving other dependencies there is also lookup facility.

Apache Hivemind is another minimalistic container, with IoC principles applied to lifecycle, configuration and automatic dependency injection, although lookup is also supported. This container is best classified as “declarative de-centralized”. It uses a special format for its components (code + XML-based descriptor). Dependency injection is supported through components following a naming convention.

Other examples of microcontainers are: Picocontainer, Butterfly, Guice.

Spring

Spring framework is a set of components aimed to be simple, lightweight and cheap alternatives to  all parts of JEE. As a a replacement of EJB it provides a much simpler IoC container. However, this container is often used not just for binding user components together, but also for binding them with system components. This was new at the time, because JEE application servers didn’t allow to customize the “system” part. Spring container is not just “business logic integration point”, but whole “application integration point”.

IoC principle in Spring could be applied to lots of concerns, including lifecycle, dependency resolving via injection, configuration. However, usage of IoC is not mandatory and could be avoided, but it will make whole arcitecture less consistent.

One interesting application of IoC principle used Spring is “aspect-oriented programming”: a container “wraps” modules with its own “proxy”, and injects this proxy into dependent modules. This “proxy” allows inserting some functionality before invocation and after invocation, so some component can affect interaction between two other modules without modifying them.

Spring is very popular, because it provides a large base for building custom server-side software, either complex or simple.

 JEE application servers

After success of Spring vendors of many JEE application servers understood that their products should be more customizable, so those servers were re-designed as microcontainers. Apache Geronimo is a microcontainer allows deployment of components called “GBeans”. JBoss also implements microcontainer architecture. Glassfish and JOnAs stated that they will move to OSGi.

Apache Geronimo is an example of “embedded container” architecture: EJB container (OpenEJB) is itself a component in another container (Geronimo microcontainer).

OSGi

The distinguishing feature of OSGi framework is a complex classloading. This allows “hot upgrade” through dynamic loading and unloading of classes, and other interesting capabilities. IoC principle is applied only to lifecycle. As a separate component there is a “service facility” which could be used for basic dependency lookup, and also allows subscription to notifications about lifecycle events in other services. There is also component for dependency injection called “Service Binder” based on XML descriptors.

There are several implementations of OSGi framework, including Eclipse Equinox and Apache Felix.

JSLEE

JSLEE is another non-generic component architecture for Java. It is similar to EJB in a way in which IoC principle is applied to persistence and lifecycle. JSLEE includes scalable event-delivery facility, and IoC principle is appled to some aspects of interfaction between components and event-delivery facility. could be viewed as a combination of Servlet Container and EJB container. Dependencies are resolved using lookup (in JNDI).

Basic and recursion

July 19, 2007

I’m still reading book about data structures in Basic. Of course, this book didn’t missed an oportunity to show one of usage for stack: recursion. As everybody can imagine, implementation of recursion in plain old Basic is horrible: hard to read, hard to understand. And finally, they demonstrate how to replace recursion with iteration. My main feeling is “never do recursion in Basic”. But reading of this chapter gave me lots of insights.

First, about recursion itself. Lots of books explain it, every Lisp book for beginners have explanation of recursion. They assume that recursion is something which is not tought in school. Yes, that’s right, in school they always prefer iterative approach. I was tough that multiplication is addition of equal values: a*n = a + a + a + … + a (n times). Same thing about factorial. Recursion here is a nice way to avoid those dots and make precise definition of repetitive process by defining such process through itself. But in those cases iteration and recursion give same results, their difference is that recursion is more beautiful but harder to understand. In programming it’s often better to use approach which is simpler to understand. Also, in Basic recursion is not as beautiful as in math, so for Basic iteration for such tasks is a better solution.

There are other cases where recursion is natural: solving “Hanoi towers”, doing binary search in lists and trees. This “naturality” comes from fact that process itself is really recursive or data structures used are recursive. Unfortunatelly, in Basic such data structures are represented in some ugly way, so their recursive nature is not helping to solve task beautifully.

Recursion is a term which belongs to semantics of data structures and algorithms. If you really want to design data structures and algorithms in this way, you should better use programming language which supports semantics of “recursion”. For data structures this means pointers/references, for algorithms it means invokations using stack.

Above is just a concrete case of principle “use tool appopriate for your task”. Nobody tries to do object-oriented programming in C. Nobody should do recursion in Basic.

Personal Wiki

June 14, 2007

I like Wikipedia. It’s fantastic! If I need information, I go there. They have information exactly in the way I need, and they also have links to look further.

Now different Wikis used everythere as a replacement to documentation. It’s editable, and knowledge is organized in small pieces connected with links. Simple and convenient. When I wanted to make my own knowledge base, I wanted it to use Wiki. But, does it mean that I need Web server, DBMS, PHP and some Wiki engine just to organize my knowledge ? Fortunatelly not.

There is a sort of software called “personal Wiki” or “desktop Wiki”. They are simple GUI tools which allow you to edit text pieces and link them one to another. Interested people can find more here. I’ve tried several of those tools and have choosen my favourite. It’s ZuluPad.

This application is minimalist, and I like that fact. It’s just a plain text editor, as simple as Notepad, but not a single continuous page. It has separate pages for each “topic”. To create new topic, just select some word, and press “Ctrl+L”, and new topic will be created dedicated to selected word. On your previous topic there will be a link to new topic. You can navigate by choosing topic from list.

Application is open source, so anybody can extend it. In fact, there is a commercial version, with different text styles and formatting, but I don’t need it. Files are stored in XML, so it’s easy to put your knowledge base online using simple XSLT.

I like personal Wikis and recommend them to anyone!