Introduction to libuv

336 views
Skip to first unread message

Nikhil Marathe

unread,
Jul 27, 2012, 2:15:27 PM7/27/12
to nod...@googlegroups.com
Hi guys,

I have been working on a sort of libuv guide book - 'An introduction
to libuv' for the past few days.
You can view it at http://nikhilm.github.com/uvbook/

Its only about half complete (lots of TODOs all over), but with the
recent spate of libuv queries,
I thought I would just put it out in the open so that people can read
the parts that are done. I
eventually want it to cover all the features libuv provides, but for
now basic I/O, TCP networking
and threads is almost complete.

At this point the book requires prior understanding of event loops,
until I polish up the introduction.
Feel free to fork and contribute or file issues with the book. Github:
https://github.com/nikhilm/uvbook.

This is the first time I'm writing something of such scope, so all the
feedback I can get is welcome.

Regards,
Nikhil

Rob Ashton

unread,
Jul 27, 2012, 2:31:27 PM7/27/12
to nod...@googlegroups.com
NICE,

Haven't clicked through yet due to being on the phone but this sounds
like a great effort!

Sent from my iPhone
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

wavded

unread,
Jul 27, 2012, 10:09:24 PM7/27/12
to nod...@googlegroups.com
Awesome, will definitely check it out!

Oleg Efimov (Sannis)

unread,
Jul 28, 2012, 4:35:49 PM7/28/12
to nod...@googlegroups.com, Ben Noordhuis, Isaac Z. Schlueter
I think it will be good to include this as part of libuv repository.

пятница, 27 июля 2012 г., 22:15:27 UTC+4 пользователь Nikhil написал:

Ilya Dmitrichenko

unread,
Jul 28, 2012, 6:34:03 PM7/28/12
to nod...@googlegroups.com
Amazing work! I hope to find some time to dive into it and see if I
can add anything :)

Alan Gutierrez

unread,
Jul 29, 2012, 12:42:58 PM7/29/12
to nod...@googlegroups.com
Outstanding Nikhil! Thank you very much. Great contribution.

--
Alan Gutierrez - @bigeasy

secoif

unread,
Jul 30, 2012, 8:21:26 AM7/30/12
to nod...@googlegroups.com
Yes. I need more exposure to how the internals of this platform work, and this is really hitting the spot for me. Thanks heaps, keep it up.

dhruvbird

unread,
Jul 30, 2012, 12:36:24 PM7/30/12
to nod...@googlegroups.com, Ben Noordhuis, Isaac Z. Schlueter
+1 for adding in the libuv repo.

Alan Gutierrez

unread,
Jul 30, 2012, 1:08:59 PM7/30/12
to nod...@googlegroups.com
-1 let it have a life of it's own.

Issues and pull requests will get confused. You have two different primary
maintainers managing two very different types of project, even if the core
subject of the repo is the same. Messy.

Alan - @bigeasy

mscdex

unread,
Jul 30, 2012, 1:24:17 PM7/30/12
to nodejs
On Jul 30, 1:08 pm, Alan Gutierrez <a...@prettyrobots.com> wrote:
> Issues and pull requests will get confused. You have two different primary
> maintainers managing two very different types of project, even if the core
> subject of the repo is the same. Messy.

Perhaps, but maybe at least there could be a link to it from the libuv
readme?

Nikhil Marathe

unread,
Jul 30, 2012, 1:28:35 PM7/30/12
to nod...@googlegroups.com
Hi,

I've already added the link to the libuv wiki. I don't think its a good
idea to merge the projects.

Nikhil

Alan Gutierrez

unread,
Jul 30, 2012, 2:10:58 PM7/30/12
to nod...@googlegroups.com
Yes. I agree. That needs to happen.

https://github.com/joyent/libuv/pull/512

Atul D. Patil

unread,
Jan 16, 2013, 2:30:31 PM1/16/13
to nod...@googlegroups.com
Hi Nikhil,

I am in the phase of development of TCP server on Windows. The server should
efficiently handle thousands of concurrent TCP connections. When I was looking
for network libraries to avoid development efforts at low level, I came across
LIBUV as a stable candidate and your book on the same :-)

I was going through your book on LIBUV. You mentioning: "Networking in libuv is
not much different from directly using the BSD socket interface"

This made me little worried. I heard LIBUV encapsulates IOCP and its easier to
work with LIBUV than working directly with BSD sockets. While, working directly
with BSD sockets involves understand nitty gritty of the IOCP, thread pools and
all that stuff.


Ok. Despite of this, let me try to put my query in shortest possible way:

In the tcp-echo-server/main.c, we start listening and get callback
on_new_connection for each new connection. Similarly, echo_read is callback we
get when each client sends us request.

Now as long as catering few thousands of connections is concerned, my question
is:

Does the library takes care of all aspects of the performance (viz. threads and
number of CPU cores, threadpool, IOCP etc.) and we end up getting "new
connection", "client request" events nicely and we just need to process them

OR

We can (or need to) do more (threads etc) in this piece of code from efficiency
and performance perspective?

Thanks,
Atul D. Patil



Nikhil Marathe

unread,
Jan 16, 2013, 4:14:21 PM1/16/13
to nod...@googlegroups.com
On Wed, Jan 16, 2013 at 11:30 AM, Atul D. Patil <atuld...@gmail.com> wrote:
> I was going through your book on LIBUV. You mentioning: "Networking in libuv is
> not much different from directly using the BSD socket interface"
>
> This made me little worried. I heard LIBUV encapsulates IOCP and its easier to
> work with LIBUV than working directly with BSD sockets. While, working directly
> with BSD sockets involves understand nitty gritty of the IOCP, thread pools and
> all that stuff.

What I meant was the the interface to libuv sockets is very similar to
the bsd socket interface, in terms of function names and arguments.
You don't need to understand IOCP, libuv will deal with it internally
on windows.
>
>
> Ok. Despite of this, let me try to put my query in shortest possible way:
>
> In the tcp-echo-server/main.c, we start listening and get callback
> on_new_connection for each new connection. Similarly, echo_read is callback we
> get when each client sends us request.
>
> Now as long as catering few thousands of connections is concerned, my question
> is:
>
> Does the library takes care of all aspects of the performance (viz. threads and
> number of CPU cores, threadpool, IOCP etc.) and we end up getting "new
> connection", "client request" events nicely and we just need to process them

libuv directly interfaces with IOCP, it does not do any of its own
thread pooling based on CPU cores.
So performance will only be as good as IOCP gives on a single thread
(since libuv is a event loop system, there is only one thread). libuv
does provide primitives to get the number of cores and to spawn
threads and have each thread have its own event loop. You can also do
the same with processes. This may increase performance

Nikhil

Eric Muyser

unread,
Jan 16, 2013, 6:13:33 PM1/16/13
to nod...@googlegroups.com
Stopped reading after the "hello world" example printed "now quitting"

Joking, looks awesome ^_^ Nice work.

Dean Mao

unread,
Jan 16, 2013, 6:20:53 PM1/16/13
to nod...@googlegroups.com
Thanks for this...  much better than reading uv.h for all the info.


Reply all
Reply to author
Forward
0 new messages