Monthly Archives: April 2018

Create a simple cache in C# .NET

Here is a little sample of code I have written to simulate a cache, wich write the data every second on disk in the background in a dedicted thread.

Using this class Engine, you can write data to the internal dictionary and keep it safe because the database is written to disk… I do not have handled the reload of the data in the ctor… Here the client program who write any number of values you want:

If I run the console application using different values, here is the result:

D:\Dev\MyCache\ConsoleApp1\bin\Debug>ConsoleApp1.exe 10
Count: 10
Time elapsed set: 0 ms
Time elapsed get: 0 ms
Writing DB…
Writing DB OK

D:\Dev\MyCache\ConsoleApp1\bin\Debug>ConsoleApp1.exe 100
Count: 100
Time elapsed set: 0 ms
Time elapsed get: 0 ms
Writing DB…
Writing DB OK

D:\Dev\MyCache\ConsoleApp1\bin\Debug>ConsoleApp1.exe 1000
Count: 1000
Time elapsed set: 1 ms
Time elapsed get: 1 ms
Writing DB…
Writing DB OK

D:\Dev\MyCache\ConsoleApp1\bin\Debug>ConsoleApp1.exe 10000
Count: 10000
Time elapsed set: 7 ms
Time elapsed get: 13 ms
Writing DB…
Writing DB OK

D:\Dev\MyCache\ConsoleApp1\bin\Debug>ConsoleApp1.exe 100000
Count: 100000
Time elapsed set: 98 ms
Time elapsed get: 140 ms
Writing DB…
Writing DB OK

D:\Dev\MyCache\ConsoleApp1\bin\Debug>ConsoleApp1.exe 1000000
Count: 1000000
Writing DB…
Writing DB OK
Time elapsed set: 3656 ms
Time elapsed get: 4023 ms
Writing DB…
Writing DB OK

Source code here: MyCache.zip

Advertisements

Programmez Magazine turns 20 years

I am proud to write for this magazine. It is written by developers for developers. The May issue is the special 20 years edition. Great Job François Tonic.

Article in Technical Magazine Programmez N° 218 – May 2018

In May 2018, you will discover a technical article How to build under 64 bits environment. It contains tips&tricks for handling the migration because the source code will not compile as easy you can think…

 

LMDB for Windows

When I discovered the fantastic history of LMDB, It fascinated me. For a R&D projet, we need to present something that looks sexy and with a strong architecture. I proposed to study LMDB and bring to it the distributed engine and the clustering stuff with nodes. There are plenty ways of acheiveing this.

First, OpenLDAP-LMDB need to be ported on the Windows platform. It’s a C based code so there are no some many changes to fix for building on Windows. There was a path concat that made some problems but it’s defined as constants so I fixed it rapidly. I put it in Github after the operation was done.: https://github.com/ChristophePichaud/LMDBWindows

I was able to build a static lib for LMDB. But in Windows, we love shared modules called DLL so I have to put some little things on the source code to enable loading shared modules DLL (Dynamic Link Library).

#ifdef LMDBWINDOWSDLL_EXPORTS
#define LMDBWINDOWSDLL_API __declspec(dllexport)
#else
#define LMDBWINDOWSDLL_API __declspec(dllimport)
#endif

With theses expanded macros, it can export functions. Every headers and bodys need to be decorated. Here is the explaination. When you build the library, you define de constant LMDBWINDOWSDLL_EXPORTS in the project settings then every macros instruct the compiler to export the functions. When you build an application who needs the dll, the macro is expanded as an import operation and at the link phase, you need to link with the little stub to attach the library.

If you are new to Windows DLLs making, check this portion of doc on MSDN: https://msdn.microsoft.com/en-us/library/a90k134d.aspx

Enter in the world of NoSQL engines

Sometimes ago, I had to discover a source code, as is. It was a database engine. A big software, powered by C/C++ using linux tools. I always install cygwin on my machines so there was no problem. Tools where Bison, lex and sed. Some bash scripts to put files on common folders & some other stuff. The storage engine was powered with LMDB. It’s the fastest engine on the market, they said in a README.MD. There was also a data structure that was associated with a registered patent.

I have read a lot of wikipedia on NoSQL engines and I have inspected a lot of source code like LMDB and Redis. It’s all about C, it’s brutal and very efficient. It fascinates me. And so what for ?

I currently work on a R&D project to put a NoSQL engine on a Windows service and install it on a Docker image and run it in Azure Container Instances (ACI). As a Micrcosoft partner, my company has to work with Azure and win competencies. Because it’s a R&D project, we have ambitions : make a Redis like software. With distributed features. We want superior performance versus DocumentDB. It will be powered by LMDB. More to come in coming weeks. Stay tuned.