SqueakSource API?

David T. Lewis lewis at mail.msen.com
Sun Feb 19 17:04:26 UTC 2006


On Sun, Feb 19, 2006 at 12:24:20PM +0100, Philippe Marschall wrote:
> 2006/2/19, Bernhard Pieber <bernhard at pieber.com>:
> > "Philippe Marschall" <philippe.marschall at gmail.com> wrote:
> > > An other intersting option this opens is it allows us to run expensive
> > > jobs like activity analysis on the second cpu.
> > I must admit that I did not understand this. Can you elaborate?
> 
> A long time ago, in a galaxy far far away, we had a realtime
> statistics graphic for SqS (number of projects, ...). You can see this
> in the SqS Paper submitted ESUG. As SqS grew to it's current size,
> this caused all kinds of problems one of them was that it is too cpu
> intensive. The code is still there, just commented out.
> SqS now runs on a dual CPU machine but we can use only one CPU,
> because we don't need no stinkin' Java threads. If we can access the
> data from outside the image, we could set up a cron job, that starts a
> script (or image) that fetches the data, computes the graphic, writes
> it to the filesystem and then terminates. We can then serve the
> graphic with apache.

cron job?!? we don't need no stinkin' cron jobs neither ;)

 [[ | pipe backgroundJob ws |
   pipe := OSPipe new.
   backgroundJob :=
     OSProcess thisOSProcess forkHeadlessSqueakAndDoThenQuit:
       [OSProcess accessor nice: 1. "lower priority of background OS process"
       (99 to: 1 by: -1) do: [:e |
         pipe nextPutAll: e asString;
           nextPutAll:' bottle';
           nextPutAll: ((e = 1) ifTrue: [''] ifFalse: ['s']);
           nextPutAll: ' of beer on the wall, ';
           nextPutAll: e asString;
           nextPutAll:' bottle';
           nextPutAll: ((e = 1) ifTrue: [''] ifFalse: ['s']);
           nextPutAll: ' of beer'; cr;
           nextPutAll: 'take one down and pass it around, ';
           nextPutAll: ((e = 1) ifTrue: ['no more'] ifFalse: [e - 1]) asString;
           nextPutAll:' bottle';
           nextPutAll: ((e = 2) ifTrue: [''] ifFalse: ['s']);
           nextPutAll: ' of beer on the wall'; cr].
         pipe close].
   Transcript show: backgroundJob asString, ' started'; cr.
   pipe closeWriter. "don't need writer end, close it before the #upToEnd"
   "pipe writer blocks when pipe full, so we need to loop while reading to end"
   ws := WriteStream on: ''.
   [backgroundJob isComplete] whileFalse:
     [(Delay forMilliseconds: 200) wait.
     pipe upToEnd ifNotNilDo: [:s | ws nextPutAll: s]].
   pipe close.
   Transcript show: backgroundJob asString,
     ' completed, display results in 2 seconds'; cr.
   (Delay forSeconds: 2) wait.
   Transcript show: ws contents.
   Transcript cr; show: 'delay 5 seconds before forking next Squeak job'; cr.
   (Delay forSeconds: 5) wait]
     repeat] forkAt: Processor userBackgroundPriority.


It's usually more efficient to do it this way, because you don't need to
start up a new image every time you run the job. It also avoids the files
and cron jobs, which IMHO are even uglier than the aforementioned Java
threads.

Dave





More information about the Squeak-dev mailing list