TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Rationale: Or why am I bothering to rewrite nanomsg?

113 点作者 aleksi大约 7 年前

11 条评论

elevation大约 7 年前
From the article:<p>&gt; nanomsg has dozens of state machines, many of which feed into others, such that tracking flow through the state machines is incredibly painful.<p>&gt; Worse, these state machines are designed to be run from a single worker thread.<p>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.<p>State machines are useful for precisely the reasons the author states: their behavior and performance are easy to reason about and state machines can enable concurrent processing of multiple tasks when when you&#x27;re limited to a single execution thread.<p>The simplicity of state machines makes them useful for secure code or embedded processes where debug visibility can be poor. Embedded environments like microprocessors also benefit from the single-thread concurrency, but this can also be handy on more capable OSs if you want to cut the latency of fork() or pthread_create().<p>State machines are a really useful tool; there are worse complaints you could make about a code base.
评论 #16797791 未加载
blattimwind大约 7 年前
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&#x2F;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.<p>Meanwhile the old&#x2F;bad&#x2F;bloated&#x2F;poorly designed zmq just kept working fine all these years and even got a bunch of useful new features along the way.
评论 #16800639 未加载
评论 #16798186 未加载
nitwit005大约 7 年前
&gt; Sadly, this initial effort, while it worked, scaled incredibly poorly — even so-called &quot;modern&quot; 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, especially if one limits the stack size appropriately. I’m used to be able to create thousands of threads without concern.<p>Both work just fine with hundreds of threads, and both offer built in thread pools, for that matter. I have 345 processes running on OS-X right now.
评论 #16797596 未加载
评论 #16797565 未加载
dmitrygr大约 7 年前
<p><pre><code> &gt; even so-called &quot;modern&quot; operating systems &gt; like macOS 10.12 and Windows 8.1 simply &gt; melted or failed entirely when creating &gt; any non-trivial number of threads. (To &gt; me, creating 100 threads should be a no-brainer </code></pre> This is nonsense. NT kernel happily creates thousands of threads. Just made a little test app to try. No issues at all.
评论 #16798104 未加载
评论 #16798623 未加载
评论 #16797855 未加载
评论 #16797889 未加载
评论 #16797912 未加载
nfoz大约 7 年前
Do people generally consider nanomsg to be a &quot;failed experiment&quot;? Is anyone using it for their projects?<p>The author&#x27;s tone makes it seem like I shouldn&#x27;t use nanomsg. nanomsg in turn makes it seem like I shouldn&#x27;t use ZeroMQ.<p>So what would people recommend me to use right now for a project? Are these issues all that serious?<p>My intended use would be for a simple friendly pub-sub API for programs to talk to each other, locally or across a network.
rumcajz大约 7 年前
Original author of zmq&#x2F;nanomsg here.<p>After all those years dealing with the problem of implementing network protocols I believe that this entire tangle of problems exists because we are dealing with something like 35 years of legacy in two different but subtly interconnected areas: concurrency&#x2F;parallelism and network programming APIs.<p>The area of concurrency&#x2F;parallelism started quite reasonably with the idea of processes. But then, at some point, people felt that processes are too heavy-weight and introduced threads (I&#x27;m still trying to find out who the culprit is, but it looks like they&#x27;ve covered their tracks well.) When even threads became too heavy-weight people turned to all kinds of callback-driven architectures, state-machine-driven architectures, coroutines, goroutines etc. Now we have all of those gand we are supposed to make them work together flawlessly, which is a doomed enterprise from the beginning.<p>At the side of network programming, BSD sockets (introduced in 1983) are the only common ground we have. They are long past their expiry date, they don&#x27;t adapt to many use cases, but there&#x27;s no alternative. There are more modern APIs there, but, AFAICS, none of them provides enough added value of top to become the new universal standard.<p>It should be also said that creation of new universal APIs is hindered by a host of weird network protocol designs out there in the wild. The API designer faces a dilemma: either they go for sane API and rule at least some weird protocols out or they try to support everything and end up with one mess of an API. Not a palatable choice to make.<p>Then there&#x27;s the area where the two problems about interact. Originally, you were supposed to listen for incoming TCP connections, fork a new process for each one and access the socket using simple single-threaded program with no state machines, using only blocking calls. Today, you are supposed to have a pool of worker threads, listen on file descriptors using poll&#x2F;epoll&#x2F;kqueue, then schedule the work to the worker pool by hand. This raises the complexity of any network protocol implementation by couple of orders of magnitude. Also, you get a lot of corner cases, undefined behaviour, especially at shutdown, weird performance characteristics and I am not even speaking of the increased attack surface.<p>All in all, it&#x27;s a miracle that with the tools we have we are able to write any network applications at all.<p>These days I am working on attacking the issue on both fronts. On the concurrency side it&#x27;s <a href="http:&#x2F;&#x2F;libdill.org" rel="nofollow">http:&#x2F;&#x2F;libdill.org</a> -- esentially not very interesting, just an reimplementation of goroutines for C, however, what&#x27;s worth looking at is the idea of &quot;structured concurrency&quot;, a system of managing the lifetimes of coroutines in a systemic manner: <a href="http:&#x2F;&#x2F;libdill.org&#x2F;structured-concurrency.html" rel="nofollow">http:&#x2F;&#x2F;libdill.org&#x2F;structured-concurrency.html</a><p>On the other front, the network programming, I am trying to put together a proposal for revamp of BSD socket API. The goal is to make it possible to layer many protocols on top of each other as well as one alongside the other. It&#x27;s a work in progress, so take it with a grain of salt: <a href="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;sustrik&#x2F;dsock&#x2F;master&#x2F;rfc&#x2F;sock-api-revamp-01.txt" rel="nofollow">https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;sustrik&#x2F;dsock&#x2F;master&#x2F;rfc&#x2F;s...</a>
评论 #16799856 未加载
评论 #16799632 未加载
评论 #16799508 未加载
e12e大约 7 年前
Looks interesting, especially the Zerotier transport. Although I wonder why that&#x27;s needed&#x2F;what it means: with Zerotier you already have ip4&#x2F;6 connectivity - what&#x27;s the benefit of burying down below that?<p>Would that mean a &quot;wireguard transport&quot; would make sense as a default secure transport?<p>My other concern is that this starts to sound very big - have you been able to maintain clear modularisation of the code?
评论 #16797084 未加载
daurnimator大约 7 年前
&gt; OpenSSL has it’s own struct BIO for this stuff, and I could not see an easy way to convert nanomsg&#x27;s usock stuff to accomodate the struct BIO.<p>It&#x27;s actually quite easy to write a custom BIO to work with your own state machines and buffering. This could have been a 1-day project....
theincredulousk大约 7 年前
This is at least partially ill-advised. Comes off as an expertly done, but same old refactoring project that could be titled &quot;I didn&#x27;t understand this and would understand it better if I were designed based on my personal preferences&quot;. This is reinforced by the probably approaching 1 that nobody needs another &quot;six of one half dozen of the other&quot; message queue framework, and alluding to an belief that the C++ library is somehow too bloated for embedded environments. While that was at a time true, no reasonably modern embedded system that requires multi-threading to &quot;100s&quot; of threads, or uses 100s of live sockets for message queue I&#x2F;O, has to avoid C++ for being too heavy. This is just ZeroMQ alternative #N - not anything objectively better, and certainly not &quot;nano&quot; for embedded systems. The &quot;one true messaging framework&quot; is a unicorn - everyone feels like it should exist but nobody can make it.<p><i>But for many cases this is not necessary. A simple callback mechanism would be far better, with the FDs available only as an option for code that needs them. This is the approach that we have taken with nng.</i><p>Replacing a state machine with callbacks... something something something you&#x27;re gonna have a bad time. Esp. considering the gripes are about readability, following control flow, and race conditions. Callbacks are objectively worse for all of those things. Control flow <i>is</i> hard to read in state machine frameworks because the primary flow is dictated by something like &quot;nextState(thisState, action)&quot;, so you can&#x27;t follow it with code lookup.<p>The problem here (and almost always) is lack of documentation or visualization (or picking the wrong abstraction level for the formally defined states). The beauty is that the definition is almost by default naturally easy to parse (tables of states in a header file, etc.). It takes some extra effort, it is a one shot to write something that generates graphviz state chars or something similar from the state table definition. You could write a custom dot syntax generator from a C-style table definition in what, three hours? Doxygen already does this for much more complicated stuff. Googling reveals this is nothing new: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;freqlabs&#x2F;24d88ad8e687891c970a69f16f1387b8" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;freqlabs&#x2F;24d88ad8e687891c970a69f16f1...</a><p>All that said, State Machines are (currently) the one true abstraction for a given program because that is what a computer is, and every program is, to begin with. If you&#x27;re not using them explicitly, it just means you have a poorly defined&#x2F;documented state machine. Maybe someday there will be a better model of computing, or a better way to model programs. For now, the human brain isn&#x27;t getting any better at keeping track of computer programs, and anything more than single-threaded functional-style code is almost certainly not any &quot;absolute&quot; improvement in readability.<p>I firmly believe that visualization has become necessary due to complexity, and it is past time to embrace it. There is some stigma that visualization is for fakers - &quot;real programmers only use a bare text editor&quot; - or that it is for children learning programming, or non-engineering folks that need pictures because they&#x27;re dumb. To be a bit hyperbolic, if we want any chance at keeping up with &quot;the machines&quot;, we&#x27;re going to need a better general-purpose, more workable abstraction than text files. There is no more canonical example of this than the issues pointed out here - state machines are the right abstraction for complex systems, but complex state machines are incredibly difficult to follow in source code.
评论 #16799153 未加载
评论 #16799081 未加载
评论 #16799698 未加载
评论 #16798770 未加载
larrik大约 7 年前
I think you meant &quot;Rationale&quot;
senatorobama大约 7 年前
Can someone explain what&#x27;s so special about these libraries that make then &quot;better&quot; than raw sockets?
评论 #16797822 未加载
评论 #16798027 未加载
评论 #16798082 未加载