On Fri, May 01, 2009 at 08:46:51PM -0700, Raine Fan wrote: > Hi Nick/Niels/Libevent staff! > > > Meanwhiloe reading the great documentation of Libevent-2.0 > (http://wangafu.net/~nickm/libevent-book/) I was a bit confused on > some warnings. Could explain in more details, if possible? >
I've tried to clarify it a little. Let me see if I understand your question... > http://wangafu.net/~nickm/libevent-book/Ref4_event.html on 'Stack- > and struct-allocated events' > > > When you say that "You shouldn???t do this unless you knowthat > you???re incurring an actual performance penalty for heap-allocating > your events" instead of allocating them on the stack, what would be > the best way to do it? I shouldn't have implied that stack-allocating lots of struct event is a good idea. The typical usage pattern for event_assign() is sticking the struct event inside another structure which you then in turn heap-allocate, like the example does it. Even then, it's a fairly error prone thing that, like the document says, you should not do until you *know* it is actually an issue for your application. Have you heard the old Knuth saying, "Premature optimization is the root of all evil in programming"? Typically, it's better to write your code to be simple, maintainable, and correct, and not spend time optimizing it until you know, through actual measurement, where the performance issues lie. > If I want to scale my app on, lets say 1Millon > fd's :-) , do you think that using heap-based allocation could incur > in a great performance penalty? Probably not in comparison to everything else your program would be doing in that case. > Since I'm really new to this kind of > programing paradigm (BTW this doc is awesome!), what kind of good > tricks/advises could you dispose to us, noobies, for making a good > use of libevent to scale our apps to above the C10K paradigm? If we > are using multithreaded event-loops, using heap-allocation maybe is > the only way to pass info between the threads, or just making a large > global statically allcoated array of event-bases and let the threads > work consistently on them? If you're new to nonblocking event-based IO, I'd first suggest that you try to walk before you run. Doing multithreaded apps with multiple event bases is not a easy way to start out. As for scaling across multiple threads, that's a problem I'd really like a future version of Libevent to tackle. peace, -- Nick _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users