DOL – Delete Oldest Logs

This is a little program I made some time ago because I had some problems with some log files I generated. I didn’t know how big they would end up and I had a limited disk space. As you can guess, it can be used for any files. So I could have called it “DOF – Delete Oldest Files”.

The idea of this tiny .Net program is to delete the oldest logs first. It scans every files and delete as many files as required to reach its objectives.

Command line arguments (-h option) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
DOL - Delete Oldest Logs (first)
Arguments are :
===============
-d          : Directory where to analyse files
-dr         : Directory where to analyse files recursively
-de         : Delete empty dirs
-sm         : Sort files by modification (default)
-sc         : Sort files by creation
-sa         : Sort files by access
-ds <size>  : Delete oldest logs to reach a total size of <size> (in bytes)
-dn <nb>    : Delete oldest logs to reach a total number of <nb>
-v          : Switch to verbose mode
 
Numbers can have k,m,g :
1k = 1 024         bytes
1m = 1 048 576     bytes
1g = 1 073 741 824 bytes

So, on Windows, you will probably do somethind like :

1
dol.exe -de -dr C:\temp -ds 2g

On Linux, it’s the same thing with a “mono” before.

1
mono dol.exe -dr /var/log/apache -ds 1g

You can download it here (13.5 KB).

Posted in English. Tags: , . No Comments »

kernel event to improve network performance on .Net

I have built a simple tcp/udp network server library. I used it on lots of little programs and on one pretty important vehicle tracking server. The first version was using one thread for each connected client. It was working but it consumed a lot of memory. When the server reached something like 3000 simultanneous connections, the kernel was killing it for consuming to much memory.

I built a second version which was using network events. This allows you to directly receive network information from the kernel. It uses IOCP on Windows, epoll on Linux and kqueue on FreeBSD. This means that it’s not the program which frequently ask the kernel if there’s new data, it’s the kernel which tells the program that some new data has arrived.

The code change was pretty minimal. It’s just a little bit weird because you have to pre-allocate a buffer to allow the kernel to store data on it. I personally set a 128 bytes buffer. You have to add some BeginReceive calls everywhere and add some callbacks method.

My goal was to be able to reach 10 000 connections. After some few tests, I could reach 60 000 simulteanneous connections. The hardest part is in fact to allow the kernel to receive that many connection and to setup clients to open them. Once connections are opened, CPU consumption is always at 0% and server answers instantly to any client’s request.

That is for me the proof that .Net programs on Mono are well suited for massive network connection servers.

Posted in English. Tags: , . No Comments »

MapPoint WebService authentification with Mono

Recently, I was faced with a little problem. I built a .net program which calls a MapPoint WebService. It worked fine on Windows but failed on Mono/Linux with a “401 Unauthorized” error.

As it really made no sense, I decided to listen to the network communication. It did it with wireshark on my computer and tcpdump on the Mono/Linux host. And by looking at the header of the HTTP request, I noticed they were some slight differences.

I solved the problem by specifying some credentials and by using a particular host name for these credentials, here is the code :

1
2
3
4
5
6
var cred = new System.Net.NetworkCredential("---user---", "---password---");
_credCache = new CredentialCache();
_credCache.Add( new Uri( "http://findv3.staging.mappoint.net" ), "Digest", cred );
_finder = new FindServiceSoap();
_finder.Credentials = _credCache;
_finder.PreAuthenticate = true;