[zeromq-dev] C# Usage

Matthew Darnall dnallicus at gmail.com
Tue Jun 10 22:29:10 CEST 2014


Hi,

Since someone asked for use cases, I thought I would mention how I use
clrzmq and netmq.

We use NetMQ from the master branch and clrzmq 3.2.2-rc2 (with a custom
libzmq that increased FD_SETSIZE) at my work to pass data around some of
our servers.  We initially used clrzmq because we started back in July 2013
when netMQ was still quite young.  More recently, we switched to NETMQ for
one of our servers because we wanted it to run in 64 bit and rather than
figure out a way to have clrzmq load the 64 bit libzmq, we decided to use
netMQ (which we wanted to switch to anyways because it is now more actively
maintained and is pure .NET).

Our usage of the library is pretty simple, which is why we could use netMQ
and clrzmq simultaneously.  We have one C# class that wraps a ROUTER or
DEALER socket.  It monitors the socket and prints log messages, it also
keeps track of the number of sent messages and other stats like that.  It
has a Post method to send out a byte array and an Event that you can listen
to for bytes coming in.  That is it.  When we added netmq, we just made the
class an interface and made one implementation for netmq and one for
clrzmq.  We use the netmq one on the 64 bit server, but we still use clrzmq
on our 32 bit applications (partly because we haven't needed to switch and
partly because we did find clrzmq a tiny bit faster).

Here are the issues we have come across, most of which are documented in
the repositories for the projects.

Issues with clrzmq:
- loading of the libzmq library can be tricky, especially from IIS, as it
does a search of various folders for the libzmq file and the process needs
access to these folders.  We hacked something just so it always loaded
libzmq from the folder with clrzmq for our environment.
- the library uses SpinWait to do polling on sockets.  We saw some weird
behavior when load testing many messages at once where the CPU would max
out in the SpinWait of a monitoring socket.  I changed it to be a sleep
statement with 100ms in our implementation because we only use monitoring
messages for logging and don't care if they come late.
- we send a heartbeats to a server to tell it a client is alive.  We also
have the server reply right away to a client with "message acknowledged" to
tell the client the server is up.  When a client or server is doing a lot
of CPU intensive work, we have noticed the heartbeats or acknowledgement
messages can not send for several seconds, even though they are on enqueued
on a background thread.  This issue didn't seem to happen with netmq.
- in the monitoring of a socket, some of the strings passed back can be
uninitialized memory (I think it tries to pass back the address of a closed
socket on a disconnect, but that address was freed in the C code).  We got
around this by not listening for disconnects in the monitoring of a socket.

Issues with netmq:
- most are listed here, https://github.com/zeromq/netmq/issues, the two
that affected us were the resolving of the address (localhost vs ip address
vs 127.0.0.1 etc) and the monitor events throwing nullreferenceexceptions.
- when load testing many threads at once, netMQ didn't seem to scale as
well as clrzmq. We did something like 8 clients talking to the same server,
where the server was an 8 core machine. clrzmq basically performed at the
same speed as when there was one client, netmq saw a definite slowdown (not
sure if there is some exclusive locking going on somewhere in the library).
 However, we didn't get long delays for heartbeats or acknowledgements when
pounding a server as we did sometimes with clrzmq / libzmq.

Overall, both are working well for us.  Several of the issues above just
needed some small tweaks for our use case and the larger issues only really
cropped up when we were load testing a load much higher than we use in
practice (or if it did happen in production systems, it was because someone
was doing something wrong and sending too much data).

Hope that helps.

Matt


On Tue, Jun 10, 2014 at 3:16 PM, Paulmichael Blasucci <pblasucci at gmail.com>
wrote:

> Ah, I see. That makes perfect sense. Also, thanks for the valuable
> feedback. It honestly never occurred to me to have C# (or VB) examples. I
> shall definitely make plans to add them. Oh, and -- while I think of it --
> there _is_ one C# example. But it's buried in the source for fszmq (
> https://github.com/zeromq/fszmq/tree/master/tests/fszmq.compat.cs).
> Anyway, thanks again.
>
> Happy Coding!
>
> Paulmichael
>
>
>
> On Tue, Jun 10, 2014 at 1:59 PM, Chris Hafey <chafey at gmail.com> wrote:
>
>> Hi Paulmichael,
>>   My comment about fszmq documentation lacking is based on the C#
>> perspective.  I see that "the guide" has great examples of using fszmq for
>> F#, but does not have any for C#.  All C# examples appear to be written for
>> clrzmq and I assumed they would not work for fszmq.  If that is not the
>> case (or fszmq has equivalent C# examples) please let me know!
>>
>>   Right now I am learning using clrzmq 2.2 because I wasn't sure what to
>> use (hence this thread).  Once I get a bit more comfortable with ZeroMQ
>> I'll give fszmq a try and let you know if I need any help.  Thanks!
>>
>> Chris
>>
>>
>> On Tue, Jun 10, 2014 at 11:13 AM, Paulmichael Blasucci <
>> pblasucci at gmail.com> wrote:
>>
>>> Hi Chris,
>>>
>>> I think you've summed it up rather succinctly. I do have one question,
>>> though (more of a favor, really): Can you on where or how the clrzmq
>>> documentation is more thorough (or abundant) than for fszmq? I'm not
>>> disputing your assessment. I just want to know where and how I can improve
>>> as a library author. Also, if you have further questions, this list is a
>>> great place to ask.
>>>
>>> Cheers!
>>>
>>> Paulmichael
>>>
>>>
>>>
>>> On Tue, Jun 10, 2014 at 9:26 AM, Chris Hafey <chafey at gmail.com> wrote:
>>>
>>>> Hi Pieter,
>>>>   Being a C# user brand new to ZeroMQ, it wasn't clear to me how to get
>>>> started and I would be happy to help by updating the wiki.  Here is my
>>>> understanding of the situation:
>>>>
>>>> 1) There is no one "official" C#/.NET ZeroMQ library.  ZeroMQ is a
>>>> community project and individual communities support and maintain their own
>>>> libraries.  The core/mainline zeromq development is done in the c library
>>>> and updates cascade down to the other libraries as each library community
>>>> implements it.
>>>> 2) There are several C#/.NET ZeroMQ libraries to choose from each with
>>>> different pros and cons.  All but NetMQ depend on the C zeromq library
>>>> which can be a pro or con depending upon your needs.  The con could be the
>>>> dependency on a native dll.  The pro could be having the latest / most up
>>>> to date functionality and bug fixes.
>>>>    - clrzmq 2.2 - Pros: Stable, well documented and officially
>>>> released.  Cons: Old version, no longer maintained
>>>>    - clrzmq 3.0 - Pros: Stable and well documented.  Cons: Not
>>>> officially released, no longer maintained, ZeroMQ mainline no longer
>>>> compatible with 3.0??
>>>>    - fszmq - Pros: Stable, active community, F# specific features
>>>>  Cons: documentation lacking compared to clrzmq
>>>>    - NetMQ - Pros: 100% .net implementation, generally works, active
>>>> community.  Cons: Still in development and may not be suitable for
>>>> production?, documentation lacking compared to clrzmq
>>>> 3) For a C# developer brand new to zeromq and trying to learn it, it is
>>>> recommended to start with the clrzmq 3.0 prerelease version because it is
>>>> well documented and there are many good examples of its use.  Once you get
>>>> familiar with ZeroMQ, you should consider switching to fszmq or netmq which
>>>> both have active communities behind them.
>>>>
>>>> I am sure I got some of this wrong so please don't be offended if I
>>>> misinterpreted the state of things!  Please reply to this thread with any
>>>> corrections and I'll update the wiki.  Thanks
>>>>
>>>> Chris
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Jun 10, 2014 at 7:30 AM, Pieter Hintjens <ph at imatix.com> wrote:
>>>>
>>>>> Chris,
>>>>>
>>>>> NetMQ is certainly part of the ZeroMQ community and lives at
>>>>> https://github.com/zeromq/netmq, and is actively maintained. I hear
>>>>> good things about it though like anything, you'll want to try for
>>>>> yourself.
>>>>>
>>>>> Similarly, fszmq is another "official" community project and may be
>>>>> what you want.
>>>>>
>>>>> The wiki pages are edited by users, so feel free to add/correct any
>>>>> information you feel is missing or outdated.
>>>>>
>>>>> -Pieter
>>>>> _______________________________________________
>>>>> zeromq-dev mailing list
>>>>> zeromq-dev at lists.zeromq.org
>>>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> zeromq-dev mailing list
>>>> zeromq-dev at lists.zeromq.org
>>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>
>>>>
>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140610/36d593ea/attachment.htm>


More information about the zeromq-dev mailing list