Friday, May 15, 2009

Change your working directory

By default whenever you run a batch file, the working directory is usually the directory that contains the batch file.

However, if you drag and drop a file onto the batch file to use the dropped file as an argument, windows uses your user directory as the working directory.

This line below is probably the most awesome line to use at the start of a batch file to make the working directory point to the directory that contains the batch file no matter where it starts.

cd /d %~dp0

Thursday, May 14, 2009

Announcing mptoolkit

Since I work a lot with batch files to make my life easier, I needed a framework to do multithreaded batch files.

So I created mptoolkit.

This is an excerpt from the wiki

mptoolkit is a multi processing toolkit for windows batch files.

The toolkit consists of 3 executables that you should either, have next to your batch file, or in your system path somewhere.

The executables use files with .pid extensions to track how many processes are running and will do so directly next to the executable.

mpstart
Checks to see how many instances of mprun are running by looking for .pid files in the same directory as the executable. If it is greater than or equal to number of cores x 2, then it will wait until one of the instances of mprun finishes, effectively pausing the execution flow of your batch file. It calls mprun as a detached process to actually perform your command when it detects that it has space in the "thread pool".

mprun
Runs your command. mprun writes out it's own process ID, then runs the command you tell it by using cmd.exe /C %*. The reason mpstart and mprun are separated is because to allow execution flow to continue in the batch file, mpstart needs to exit.

mpwait
mpwait will pause execution of your batch files until all pid's are deleted from the directory. You can use this for synchronization purposes.

Example :

FOR /L %%G IN (1,1,20) DO mpstart ping localhost -n %%G -w 1000
mpwait

This example will start pings of increasing wait times of up to number of cores x 2 and wait until all are completed before exiting the batch file.

On a dual core processor, your task manager should look something like what is shown here :

From mptoolkit


5 cmd.exe's running - 1 for the batch process, 4 for execution

4 mprun's - actually performing the work

1 mpstart - currently in waiting for one of the previous mprun's to finish working.

Tuesday, May 12, 2009

SVN on XAMPP

XAMPP's standard apache.conf isnt really set up for svn. It's memory usage grows and grows and will eventually blow up.

The default is


# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum  number of requests a server process serves
ThreadsPerChild 250
MaxRequestsPerChild  0

I change it to

ThreadsPerChild 64
MaxMemFree 100
MaxRequestsPerChild  0
Win32DisableAcceptEx

and everything seems to work fine.