Latest posts

A Funny History of Programming Languages

Some excerpts:

1940s – Various “computers” are “programmed” using direct wiring and switches. Engineers do this in order to avoid the tabs vs spaces debate.

1964 – John Kemeny and Thomas Kurtz create BASIC, an unstructured programming language for non-computer scientists.

1965 – Kemeny and Kurtz go to 1964.

1972 – Dennis Ritchie invents a powerful gun that shoots both forward and backward simultaneously. Not satisfied with the number of deaths and permanent maimings from that invention he invents C and Unix.

1995 – Brendan Eich reads up on every mistake ever made in designing a programming language, invents a few more, and creates LiveScript. Later, in an effort to cash in on the popularity of Java the language is renamed JavaScript.

Original post, via One Div Zero.
Recommended by my great friend Arsinoé Wilche. ;-)


Job Scheduler to Network Nodes

Last post I mentioned the topic distributed systems was involved in my new project.
Now here it goes.

After setting up a small (16-machine) cluster at UNIFEI (will post about it soon) for academic experiments, the time has come for running stuff in it.
Since manually submitting and verifying jobs is very inefficient (tedious, sluggish and fail-prone), a job scheduler was required.

There are a many tools for cluster management (special thanks to Walbon) featuring job schedulers, but all too sophisticated for this application.
For this reason and 2 more, I decided to create the job scheduler. The other 2 reasons?

  • It is a not a that-difficult task
  • I’m a C programmer, and as so I like to recreate everything.. (lol)
  • It would be so much fun! (Ok. This would be a third reason.. but actually it is emotion. ;-)

It took between 16 and 20 hours to design, implement and bugfix (see Important in Scheduler).

Design

  • Dispatch a job (shell command) to an available node (using blocking-semantics)
  • Only shell script (ssh, named pipes)
  • Monitor nodes’ current activity (start time, job)

Usage

# Launch Scheduler
$ cd scheduler/
$ mkfifo jobs nodes
$ ./sched.sh
 
# Add nodes to the node pipe
$ echo "10.0.0.1" > nodes &
$ echo "10.0.0.2" > nodes &
 
# Add jobs to the job pipe
$ echo "process /folder/data.txt" > jobs &
$ echo "make -j9" > jobs &
 
# Watch the scheduler :-)

Implementation

  • Dispatcher
#!/bin/bash
 
# dispatch.sh
#
# This is a job dispatcher to network nodes.
#
# (C) Copyright 2010, Mauricio Faria de Oliveira
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation;
 
# Variables
node_pipe="nodes"
 
# Parameters
node="$1"
shift
job="$@"
 
# Checks
#	1. Parameters.
if [ "$node" == "" || "$job" == "" ]; then
    echo "Usage: $0 node job"
    exit 1;
fi
 
# Log
echo ".. (dispatch) node '$node': '$job'"
 
# Dispatch job to node via ssh
ssh "$node" "$job" > /dev/null
 
# Put node back into nodes named pipe
echo "$node" > "$node_pipe"
  • Scheduler
#!/bin/bash
 
# sched.sh
#
# This is a 2-fifo-blocking job-scheduler to network nodes.
#
# (C) Copyright 2010, Mauricio Faria de Oliveira
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation;
 
# Variables
job_pipe="jobs"
node_pipe="nodes"
dispatcher="./dispatch.sh"
 
# Checks
#	1. Check if named pipes exist.
 
if [ ! -p "$job_pipe" -o \
     ! -p "$node_pipe" ];
then
    echo "Check for the fifos 'jobs' and 'nodes' (mkfifo jobs; mkfifo nodes)"
    exit 1;
fi
 
# Algorithm
#
#	1. For each available job ('jobs' named pipe, blocking),
#	2. For an available node ('nodes' named pipe, blocking),
#	3. Dispatch job to node (asynchronously).
#
# Important
#
#	1. The named pipes are NOT guaranteed to be 'fifo'.
#		Jobs and nodes are added/return asynchronously.
#		Only the blocking behavior is guaranteed.
#
#	2. There is no way to remove a single line from a named pipe, [is it?]
#		Then:
#		1. All lines are removed,
#		2. First line is used,
#		3. Other lines are put back (asynchronously).
#
#	3. If the 'cat <> jobs' hangs for even a little while
#		jobs in this little while are lost. [why?]
#		So things are asynchronous inside this loop.
#
#	4. Never use >> (append) asynchronously with named pipes.
#		It _seems_ append on pipes works as follows:
#		1. Buffer contents
#		2. Add new stuff to buffer
#		3. Overwrite contents with buffer
#
#		If something is removed (i.e. 'cat') between steps 1 and 3,
#		it will be inserted back on step 3, due to content buffering.
#
###############################################################################
# Code                                                                        #
###############################################################################
 
#	1.	For each available job ('jobs' named pipe, blocking),
cat <> "$job_pipe" | while read job; do
 
    echo
    echo "(job): $job"
 
    # 2. For an available node ('nodes' named pipe, blocking),
 
    # 2.1. All lines are removed,
    linecount=0
    cat "$node_pipe" | while read node; do
        echo -n ".. (node): $node (#${linecount}) "
 
        # 2.2. First line is used,
        if [ "$linecount" == "0" ]; then
 
            # 3. Dispatch job to node (asynchronously).
            echo "(dispatch)"
            $dispatcher $node $job &
 
        # 2.3. Other lines are put back.
        else
            echo "(put back)"
            echo "$node" > nodes &
        fi
 
        linecount=$(($linecount + 1))
 
    done
 
    echo
 
done
  • Monitor
    Scheduled for a next post. ;-)

Will be back soon!


Linux on 8-core

There’s a new project comin’ on.
In advance: linux, data structures, distributed systems.

Linux bootscreen displaying 8 penguins

Linux bootscreen displaying 8 penguins (cores)

Gonna post about it soon.
It rocks.. You bet! :-)


IE for Windows

[10:31] Marcelo Fantini Xavier: Cara.. preciso ficar com ie7 no windows 7
[10:31] Marcelo Fantini Xavier: rssrsr
[10:31] Marcelo Fantini Xavier: tem idéia?
[10:31] Marcelo Fantini Xavier: Já procurei mais não achei nada a respeito
[10:31] Marcelo Fantini Xavier: Daqui a pouco vou tentar tirar o IE8 por completo e instalar o 7
[10:32] Marcelo Fantini Xavier: Mais aparentemente isso não funciona
[10:32] Mauricio: Pro XP tinha um programinha que instalava 6 <= IE <= 8 e coloca atalhos pra cada versão no desktop.
[10:32] Mauricio: Multi IE, algo assim
[10:32] Mauricio: usei na .
[10:33] Mauricio: google multiple ie versions
[10:33] Mauricio: [pensando] acho que nesse caso nao precisa por ‘for windows’
[10:33] Mauricio: eiauheAIeaiuhea


On God and Portable Software

If we think of the Spirit as software and the Body as hardware,
it’s clear in Spiritism that God makes portable software.