Distributed programming

Introducing ZeroMQ with C# and Java native port

Zeromq is a messaging library written in C++ for building distributed applications. The library can be used when performance and stability both matters. In addition to the original library, there are bindings in language such as C# or Java that wraps the C++ dll. Moreover, 100% native ports exists in these same languages. In this post, I will use Jeromq (Java) and Netmq (.Net) to make a client and a server communicate in a very simple request-reply pattern.

The server in C#

We need to download the latest version of Netmq via Nuget. The server binds to an address so that client can connect to it, receives a message (the request) and sends a message (the reply).

The client in Java

We need to include the dependencies in the Maven file pom.xml.

Then we can create the client application. The client connects to the server, sends a message (the request), and receives a message (the reply).

Zeromq and their related ports can also be used in other patterns like publish-subscribe, push-pull, exclusive pair, etc… This might be a topic of an other post …

Advertisements
Concurrent Programming

A quick review of the Concurrency Visualizer in Visual Studio 2015

The Concurrency visualizer is a free extension available in Visual Studio 2015 that can be used to analyse the performance of a concurrent application. I am going to do a simple overview of this extension.

The tested code

This is the code I am going to profile with the extension. It basically creates four non blocking tasks that compute 1 x 1 infinitely. The main thread then waits for user input.

Concurrency Visualizer in action

CPU Utilization shows that nearly 100% of four cores are used.

cv_cpu_utilization

The profile reports shows that four CLR worker threads (9664, 6352, 5168, and 9724) in execution most of the time, and the main thread waits for I/O most of the time.

cv_threads_view_1

Clicking on a particular worker thread at a particular time shows the call stack.

cv_threads_view_call_stack

The core view show that threads switches cores while running. More specifically, our four worker threads have more than one third of their context switches that cross cores.

cv_core_view

Concurrency visualizer helps identify problems like : serialized execution (thread executing one at a time), poor work distribution, over subscription (too many active threads), overuse of I/O, inefficient synchronization (lock convoys). It seems like a great tool!