Monday, May 23, 2011

Nice link to increas the linux fd limit -

http://www.cs.uwaterloo.ca/~brecht/servers/openfiles.html


Tuning file descriptor limits on Linux

Linux limits the number of file descriptors that any one process may open; the default limits are 1024 per process. These limits can prevent optimum performance of both benchmarking clients (such as httperf and apachebench) and of the web servers themselves (Apache is not affected, since it uses a process per connection, but single process web servers such as Zeus use a file descriptor per connection, and so can easily fall foul of the default limit).
The open file limit is one of the limits that can be tuned with the ulimit command. The command ulimit -aS displays the current limit, and ulimit -aH displays the hard limit (above which the limit cannot be increased without tuning kernel parameters in /proc).
The following is an example of the output of ulimit -aH. You can see that the current shell (and its children) is restricted to 1024 open file descriptors.

core file size (blocks)     unlimited
data seg size (kbytes)      unlimited
file size (blocks)          unlimited
max locked memory (kbytes)  unlimited
max memory size (kbytes)    unlimited
open files                  1024
pipe size (512 bytes)       8
stack size (kbytes)         unlimited
cpu time (seconds)          unlimited
max user processes          4094
virtual memory (kbytes)     unlimited

Increasing the file descriptor limit

The file descriptor limit can be increased using the following procedure:

  1. Edit /etc/security/limits.conf and add the lines:
    *       soft    nofile  1024
    *       hard    nofile  65535
    
  2. Edit /etc/pam.d/login, adding the line:
    session required /lib/security/pam_limits.so
    
  3. The system file descriptor limit is set in /proc/sys/fs/file-max. The following command will increase the limit to 65535:
    echo 65535 > /proc/sys/fs/file-max
    
  4. You should then be able to increase the file descriptor limits using:
    ulimit -n unlimited
    
    The above command will set the limits to the hard limit specified in /etc/security/limits.conf.
Note that you may need to log out and back in again before the changes take effect.


  1. [Find out where __FD_SETSIZE is defined]
    % grep "#define __FD_SETSIZE" /usr/include/*.h /usr/include/*/*.h
    /usr/include/bits/types.h:#define __FD_SETSIZE  1024
    /usr/include/linux/posix_types.h:#define __FD_SETSIZE   1024
    
    Alternately your system may use tabs in which case
    something like this should do the trick:
    % grep -E "#define\W+__FD_SETSIZE" /usr/include/*.h /usr/include/*/*.h
    [Thanks to madRat for this tip].
    
    
    [Make a local copy of these files]
    % cp /usr/include/bits/types.h include/bits/types.h
    % cp /usr/include/linux/posix_types.h include/linux/posix_types.h
    
    [Modify them so that they look something like
    #define __FD_SETSIZE  65535
    
    [Recompile httperf and/or your server so that it uses a larger file
    descriptor set size by using -I include during compliation, this
    will allow the compiler/preprocessor to use the new include files
    rather than the default versions]
    
    
  2. To check and modify limits per shell.
    [Using csh: openfiles and descriptors show that the limit here is 1024]
    % limit
    cputime         unlimited
    filesize        unlimited
    datasize        unlimited
    stacksize       8192 kbytes
    coredumpsize    0 kbytes
    memoryuse       unlimited
    descriptors     1024 
    memorylocked    unlimited
    maxproc         8146 
    openfiles       1024 
    
    [To increase this to 65535 for all users (as root)]
    # vi /etc/security/limits.conf
    
    [Modify or add "nofile" (number of file) entries - note
    that a userid can be used in place of *]
    *                soft    nofile          65535
    *                hard    nofile          65535
    




Tuesday, May 17, 2011

A simple png encoder in java

Wednesday, April 20, 2011

Wow, Michael Abrash's graphics programming black book is available here
http://www.gamedev.net/page/resources/_/reference/programming/140/283/graphics-programming-black-book-r1698
Couple of quick tips -

To concat multiple pdfs -
gs --sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite-sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf [...]


I got it from - 
http://doeidoei.wordpress.com/2009/04/12/easy-way-to-concatenate-pdf-files-in-ubuntu-linux/

Second ... httperf complaining about unavailable file handles - check out
http://gom-jabbar.org/articles/2009/02/04/httperf-and-file-descriptors
and http://www.cs.uwaterloo.ca/~brecht/servers/openfiles.html

Wednesday, April 13, 2011

Even better is http://www.bolet.org/jgz/index-en.html - much more modular hence easier to understand

Monday, April 11, 2011

I found a pure ruby implementation of zlib - https://github.com/djberg96/pr-zlib -  god bless the authors

I'm gonna try a Haskell port :)
lmbench

looks like we need to get into the results dir and do a make summary to get human readable results.

Monday, March 07, 2011

Haskell Parsec

I am going to illustrate the usage of Parsec to parse an expression into an AST. Something that took me quite a while to come up with (with help from the cafe) - Hoping, someone will find this useful

http://legacy.cs.uu.nl/daan/download/parsec/parsec.html has a sample for expression parsing - but that evaluates the expression.

And if you have not looked at http://www.cse.chalmers.se/edu/year/2010/course/TDA341/Papers/parser-hutton.ps - please do so, and fall in love with Haskell all over again :)

Say you have created an AST as follows -


data Tree a = Nil | Node a (Tree a ) (Tree a) deriving (Show)
data Element = Number Float | Plus | Minus | Multiply | Divide deriving (Show)
type AST = Tree Element


And given an expression 1+2, you need to parse it into the above mentioned AST -

Right (Node Plus (Node (Number 1.0) Nil Nil) (Node Multiply (Node (Number 2.0) Nil Nil) (Node (Number 3.0) Nil Nil)))


Full code for it is here - https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/parsec/FormParse.hs

Beautiful, is it not!

Sunday, January 17, 2010

I finally got around to play with Midi Haskell...

cabal install Haskore ...

then downloaded Haskore package from hackage and tried out a couple of programs in the examples dir ... they beautifully generate midi files!!!

I think I need to revisit the Haskell School of Expression!

Followers