elgato
Joined: 29 Dec 2007 Posts: 20
|
Posted: Fri Feb 08, 2008 12:00 pm Post subject: httpserver + dbi |
|
|
Hi, i'm trying to do multithreaded http-server with connections to database, this is what i get:
Code:
Code: |
import tango.core.Thread;
import tango.net.http.HttpConst;
import tango.util.log.Configurator;
import mango.net.http.server.HttpServer,
mango.net.http.server.HttpRequest,
mango.net.http.server.HttpResponse,
mango.net.http.server.HttpProvider;
import dbi.mysql.all;
import dbi.Row;
void main ()
{
// our simple http hander
class Provider : HttpProvider
{
override void service (HttpRequest request, HttpResponse response)
{
MysqlDatabase db = new MysqlDatabase();
db.connect("dbname=mysql;host=localhost;port=3306","root","");
db.close();
response.sendError (HttpResponses.OK);
}
}
// bind server to port 8080 on a local address
auto addr = new InternetAddress (4666);
// create a (1 thread) server using the ServiceProvider to service requests
auto server = new HttpServer (new Provider(), addr, 100, 100);
// start listening for requests (but this thread does not listen)
server.start;
}
|
Doing ab -c 100 -n 100 'http://localhost:4666/' goes ok, but making -c 100 -n 1000 and even -c 5 -n 1000 throws a segfault
Code: | [root@localhost test]# ./httpserver
Attempting to register MysqlDatabase in Registry
10 Info http.server - Server http::raw started on 0.0.0.0:4666 with 100 accept threads and 100 backlogs
Segmentation fault
|
Does anyone know how to make correct multithreaded http server with db connections? |
|