[Libevent-users] multithreading problem

2012-12-16 Thread Björn K .
Hello,

I'm trying to write a simple https server which utilizes multiple cpu cores.
I call evthread_use_pthreads() and create several pthreads. My
acceptcb and the thread worker functions are below.
For some simple test cases it works. If I use a tool like apache ab
for a perfomance test, I get some weird problems. Running the server
on OS X 10.8.2 the system becomes unresponsive. I can scroll in open
windows, but opening new windows or killing the server isn't possible.
Testing it on an actual Debian Linux with gdb shows a "glibc detected
corrupted double-linked list" error and the server receives a SIGSEGV.
I tried 2.1.1 alpha and 2.1.2 alpha. (I need the 2.1 branch because of
the new EVLOOP_NO_EXIT_ON_EMPTY.)

Thanks,
Björn

=
Code
=

static void acceptcb(struct evconnlistener *listener, int sock, struct
sockaddr *sa, int sa_len, void *arg) {

struct bufferevent *bev;
SSL_CTX *server_ctx;
SSL *client_ctx;

server_ctx = (SSL_CTX *)arg;
client_ctx = SSL_new(server_ctx);

bev = bufferevent_openssl_socket_new(thread_base[nextFree(threads)],
sock, client_ctx,
 BUFFEREVENT_SSL_ACCEPTING,

BEV_OPT_CLOSE_ON_FREE|BEV_OPT_THREADSAFE);

bufferevent_setcb(bev, readcb, NULL, NULL, NULL);
bufferevent_enable(bev, EV_READ);

}


static void *worker(void *ptr) {

struct event_base **evbase = (struct event_base **)ptr;
*evbase = event_base_new();

event_base_loop(*evbase, EVLOOP_NO_EXIT_ON_EMPTY);

pthread_exit(NULL);

}
***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.


Re: [Libevent-users] multithreading problem

2012-12-16 Thread Thomas Dial
Try JMeter.  I believe AB has bugs. 

Sent from my iPhone

On Dec 16, 2012, at 10:52 AM, Björn K.  wrote:

> Hello,
> 
> I'm trying to write a simple https server which utilizes multiple cpu cores.
> I call evthread_use_pthreads() and create several pthreads. My
> acceptcb and the thread worker functions are below.
> For some simple test cases it works. If I use a tool like apache ab
> for a perfomance test, I get some weird problems. Running the server
> on OS X 10.8.2 the system becomes unresponsive. I can scroll in open
> windows, but opening new windows or killing the server isn't possible.
> Testing it on an actual Debian Linux with gdb shows a "glibc detected
> corrupted double-linked list" error and the server receives a SIGSEGV.
> I tried 2.1.1 alpha and 2.1.2 alpha. (I need the 2.1 branch because of
> the new EVLOOP_NO_EXIT_ON_EMPTY.)
> 
> Thanks,
> Björn
> 
> =
> Code
> =
> 
> static void acceptcb(struct evconnlistener *listener, int sock, struct
> sockaddr *sa, int sa_len, void *arg) {
> 
>struct bufferevent *bev;
>SSL_CTX *server_ctx;
>SSL *client_ctx;
> 
>server_ctx = (SSL_CTX *)arg;
>client_ctx = SSL_new(server_ctx);
> 
>bev = bufferevent_openssl_socket_new(thread_base[nextFree(threads)],
> sock, client_ctx,
> BUFFEREVENT_SSL_ACCEPTING,
> 
> BEV_OPT_CLOSE_ON_FREE|BEV_OPT_THREADSAFE);
> 
>bufferevent_setcb(bev, readcb, NULL, NULL, NULL);
>bufferevent_enable(bev, EV_READ);
> 
> }
> 
> 
> static void *worker(void *ptr) {
> 
>struct event_base **evbase = (struct event_base **)ptr;
>*evbase = event_base_new();
> 
>event_base_loop(*evbase, EVLOOP_NO_EXIT_ON_EMPTY);
> 
>pthread_exit(NULL);
> 
> }
> ***
> To unsubscribe, send an e-mail to majord...@freehaven.net with
> unsubscribe libevent-usersin the body.
***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.


Re: [Libevent-users] multithreading problem

2012-12-16 Thread Nick Mathewson
On Sun, Dec 16, 2012 at 10:52 AM, Björn K.  wrote:
> Hello,
>
> I'm trying to write a simple https server which utilizes multiple cpu cores.
> I call evthread_use_pthreads() and create several pthreads

I can't tell without looking at the rest of the program, but are you
sharing one event_base among all these threads? You can't run
event_base_loop or event_base_dispatch on the same event_base from
more than one thread at once.

To do what you want, you could either have one event_base per thread,
and some mechanism to assign each incoming connection gets assigned to
a separate event_base, or you could have one event_base, and use
worker threads to do the work of actually parsing HTTP and answering
HTTP requests.

For an example of an existing library that does what you want
(multithreaded high-performance HTTP with SSL in Libevent), see Mark
Ellzey's libevhtp at https://github.com/ellzey/libevhtp .

yrs,
-- 
Nick
***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.