Live data from Hacker News

Rationale: Or why am I bothering to rewrite nanomsg?

nanomsg.github.io

11–20 of 60 posts

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#11

From the article: > nanomsg has dozens of state machines, many of which feed into others, such that tracking flow through the state machines is incredibly painful. > Worse, these state machines are designed to be run from a single worker thread. Despite the negative tone, the author gives me the impression that nanomsg as a simple, consistent architecture that just needs to be documented better or perhaps refactored.…

I came to the same conclusion more or less.

Does Go provide meaningful abstractions for writing and managing state machines? Using gen_fsm or gen_statem in Erlang is a critical tool in writing software in a way which _must_ follow some known protocol correctly. Likewise using Session-Types in Rust to go one better than what I get in Erlang (i.e. compile-time assurances vs. runtime ones).

So I was left thinking that Go may be missing meaningful abstractions or facilities for state machine modelling? Or, perhaps more of nanomsg needs to adhere even further to using state machines to define and operate its internal machinery (e.g. the `inproc` race-i-ness mentioned)?

In either case I was confused as to how the conclusion was that state machines were making everything more confusing and less deterministic. Because the point of them is the opposite of that. However, in languages or tools which have poor support for working with them I'm sure ad-hoc interaction with them can be obfuscating and confusing.

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#13

Can someone explain what's so special about these libraries that make then "better" than raw sockets?

They're not better than raw sockets, they're simply an abstraction layer on top of them.

For example, building a message queuing service using raw sockets that works on Windows, Mac OS, and Linux is quite the undertaking. With ZeroMQ (and I'm assuming nanomsg as well), it's quite simple.

ZeroMQ and nanomsg are like raw socket toolboxes.

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#14
post #9

> even so-called "modern" operating systems > like macOS 10.12 and Windows 8.1 simply > melted or failed entirely when creating > any non-trivial number of threads. (To > me, creating 100 threads should be a no-brainer This is nonsense. NT kernel happily creates thousands of threads. Just made a little test app to try. No issues at all.

Can confirm. 155 processes, 1770 threads, and 60999 handles. According to Task Manager.

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#15
post #9

> even so-called "modern" operating systems > like macOS 10.12 and Windows 8.1 simply > melted or failed entirely when creating > any non-trivial number of threads. (To > me, creating 100 threads should be a no-brainer This is nonsense. NT kernel happily creates thousands of threads. Just made a little test app to try. No issues at all.

I hear the claim pretty often that threads won't scale and that even modern OSes can't handle many threads. It makes me wonder if people are doing something different, since I've found that threads are fine.

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#16
post #9

> even so-called "modern" operating systems > like macOS 10.12 and Windows 8.1 simply > melted or failed entirely when creating > any non-trivial number of threads. (To > me, creating 100 threads should be a no-brainer This is nonsense. NT kernel happily creates thousands of threads. Just made a little test app to try. No issues at all.

I raised an eyebrow at that as well. My workstation running Windows 10 is currently chugging along with 236 Processes, 3564 Threads and 154915 Handles, which is pretty typical of this system.

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#17

Can someone explain what's so special about these libraries that make then "better" than raw sockets?

Berkeley style TCP sockets let you connect to/listen from and endpoint and transfer bytes.

That's pretty cool, but what if you want to send messages rather than raw bytes. What if you want to do publish/subscribe rather than send/receive to a single endpoint? &c.

ZeroMQ implements simple things like that that are often implemented differently in an ad-hoc manner.

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#18

Can someone explain what's so special about these libraries that make then "better" than raw sockets?

One of the features I recall liking about the ZMQ "family" of implementations is that they handle a lot of the error handling/reconnection for you.

The ZMQ guide is actually a great document to read in general terms, I recommend reading it if you are curious about the architectural rationale (which you could, actually, re-implement in your own raw socket protocol): http://zguide.zeromq.org/page:all

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#19
post #9

> even so-called "modern" operating systems > like macOS 10.12 and Windows 8.1 simply > melted or failed entirely when creating > any non-trivial number of threads. (To > me, creating 100 threads should be a no-brainer This is nonsense. NT kernel happily creates thousands of threads. Just made a little test app to try. No issues at all.

Modern operating systems are very efficient at scheduling threads with negligible workloads compared to threads that are performing under load. I suspect that a lot of test code for toy examples and default workload for thousands of threads you see on an operating system has running at any given time is probably not cpu intensive enough to matter.

Compared to this, a library designed to perform actual work using hundreds of threads on a modern os with let's say 8 cpu cores - simply won't work due to the constant context switching overhead. Consider the library called LMAX disruptor as an example of this behavior where developers need to configure threads to be equal to number of available cpus if they wish to do busy_wait processing for inbound messages on the ring buffer. Chronicle Q actually uses JNI to pin message processing threads to individual CPU cores to make sure operating system scheduling does not end up flushing L1/L2 caches and that message processing for a given queue continues to occur on the same thread/cpu combo.

So it depends on your use-case and application.

Re: Rationale: Or why am I bothering to rewrite nanomsg?

#20

I have to admit, after all these years, that I take everything coming from that general direction with a huge grain of salt. Crossroads I/O was supposed to be the great zmq successor and failed entirely, nanomsg was supposed to be an even better redesign of zmq and failed and now nanomsg-ng is supposed to be an even better design iteration on nanomsg. Meanwhile the old/bad/bloated/poorly designed zmq just kept workin…

> Meanwhile the old/bad/bloated/poorly designed zmq

Hah, zmq evolved because the developers felt amqp became to bloated.

Post reply on HN