TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

An introduction to libuv

112 pointsby deadwaitover 11 years ago

6 comments

josephgover 11 years ago
I&#x27;ve written a couple of C tools directly on top of libuv[1] to play with it. I&#x27;ve got to say, its a great little library. Its basically nodejs&#x27;s entire cross-platform standard library &amp; event loop exposed to C, without V8 and without npm. It performs well, the code is pretty high quality and the internal documentation is excellent. The external API docs aren&#x27;t very good though - I found myself reading through nodejs a few times to figure out how I was expected to use some of the functions.<p>I&#x27;m quite curious to see how much performance you lose through libuv compared to using the lower level IO primitives directly (epoll, select and friends). I know redis doesn&#x27;t use any high level event libraries, but I haven&#x27;t seen any benchmarks.<p>[1] <a href="https://github.com/josephg/sharedb" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;josephg&#x2F;sharedb</a> (Caveat: This was an experiment and libuv has probably changed in incompatible ways since I wrote this code)
评论 #6598553 未加载
jherikoover 11 years ago
i am always a bit of jerk about these things because i constantly work with genuinely performance critical code, but the very first thing puts me off:<p>uv_loop_t* loop = uv_loop_new();<p>does the compiler know where this exists, is it allocated on demand, is there a lock involved? i hope to get the good answers to these questions but the naming of the function alone makes me skeptical. this skepticism turns out to be justified.<p>digging in:<p>loop = (uv_loop_t* )malloc(sizeof(uv_loop_t));<p>so the answers to all of my questions are the wrong ones for me. i might override the allocator to be less rubbish in my context. but simple things like this tell me that this library was not architected for the kinds of performance considerations that i need to make.<p>at this high level its not so important, but the more digging i do the &#x27;worse&#x27; it gets...<p>generally this does look helpful, but it gives me nothing over my existing solutions (in my context) which, for example, require zero run-time memory allocations - outside of OS level API calls that I have zero control over - and lean heavily towards lockless implementations, avoiding the massively (but understandably) heavyweight OS provided threading primitives...<p>thread safety of malloc and other standard library (i.e. libc) type stuff is, in reality, up to the implementor. even when things have no requirement to be thread safe implementors (Microsoft) will often insert what i call &#x27;sledgehammer thread safety&#x27; to protect bad programmers from themselves. i can understand why, but it prevents me from being able to use these libraries.<p>when i can do a better job than your standard library, you have failed imo. but it is just my opinion...
评论 #6598527 未加载
评论 #6598300 未加载
评论 #6599551 未加载
评论 #6598611 未加载
评论 #6603341 未加载
评论 #6599121 未加载
kyberiasover 11 years ago
Is there some introductory text available explaining what is the purpose of libuv, it&#x27;s intended usage scenarios etc.?
评论 #6598042 未加载
评论 #6597992 未加载
评论 #6599230 未加载
the1over 11 years ago
<a href="http://redis.io/topics/internals-rediseventlib" rel="nofollow">http:&#x2F;&#x2F;redis.io&#x2F;topics&#x2F;internals-rediseventlib</a> ae is good too.
malkiaover 11 years ago
Isn&#x27;t this example wrong: (I&#x27;m not much familiar with libuv, but reading from the comments it might be):<p><a href="http://nikhilm.github.io/uvbook/filesystem.html" rel="nofollow">http:&#x2F;&#x2F;nikhilm.github.io&#x2F;uvbook&#x2F;filesystem.html</a><p><pre><code> void on_read(uv_fs_t *req) { uv_fs_req_cleanup(req); &#x2F;&#x2F; &lt;-- bug? freeing here, later using req ptr? if (req-&gt;result &lt; 0) { fprintf(stderr, &quot;Read error: %s\n&quot;, uv_strerror(uv_last_error(uv_default_loop()))); } else if (req-&gt;result == 0) { uv_fs_t close_req; &#x2F;&#x2F; synchronous uv_fs_close(uv_default_loop(), &amp;close_req, open_req.result, NULL); } else { uv_fs_write(uv_default_loop(), &amp;write_req, 1, buffer, req-&gt;result, -1, on_write); } }</code></pre>
评论 #6612471 未加载
galapagoover 11 years ago
It looks like the BeBook.
评论 #6601738 未加载