digitalmars.D - HTTP4D embedded http provider
- "goughy" <goughy gmail.com> Apr 15 2012
- Brad Anderson <eco gnuk.net> Apr 16 2012
- "goughy" <goughy gmail.com> Apr 16 2012
Hi,
I have just finished the first cut of an HTTP library to provide
application level support for HTTP (ie as a server, not a
client). The library provide a very simple mechanism for
processing HTTP requests both synchronously (via delegates) and
asynchronously (via std.concurrency) using request/response
objects.
eg.
import std.stdio;
import protocol.http;
int main( string[] args )
{
httpServe( "127.0.0.1", 8888,
(req) => req.getResponse().
status( 200 ).
header( "Content-Type", "text/html" ).
content(
"<html><head></head><body>Processed ok</body></html>" ) );
return 0;
}
The code is available on github:
https://github.com/goughy/d/tree/master/http4d
Note that this is alpha quality code, so YMMV. I would
appreciate some feedback, critiques, opinions etc. - particularly
in the area of it being "idiomatic" as I'm still finding my feet
in the D language.
The good thing is without any real performance tuning, I can push
through over 23,000 requests per second, and I'm sure there is
plenty of room for improvement.
Cheers.
Apr 15 2012
--f46d040124ab5840fa04bdc7037a Content-Type: text/plain; charset=ISO-8859-1 On Sun, Apr 15, 2012 at 6:27 AM, goughy <goughy gmail.com> wrote:Hi, I have just finished the first cut of an HTTP library to provide application level support for HTTP (ie as a server, not a client). The library provide a very simple mechanism for processing HTTP requests both synchronously (via delegates) and asynchronously (via std.concurrency) using request/response objects. eg. import std.stdio; import protocol.http; int main( string[] args ) { httpServe( "127.0.0.1", 8888, (req) => req.getResponse(). status( 200 ). header( "Content-Type", "text/html" ). content( "<html><head></head><body>**Processed ok</body></html>" ) ); return 0; } The code is available on github: https://github.com/goughy/d/** tree/master/http4d <https://github.com/goughy/d/tree/master/http4d> Note that this is alpha quality code, so YMMV. I would appreciate some feedback, critiques, opinions etc. - particularly in the area of it being "idiomatic" as I'm still finding my feet in the D language. The good thing is without any real performance tuning, I can push through over 23,000 requests per second, and I'm sure there is plenty of room for improvement. Cheers.
(though I too am still trying to get a feel for idiomatic D). How does 23,000 requests/sec compare to, say, nginx's performance (which seems to be the current performance king)? I just tried to look up some general performance figures but they are all over the place and don't correspond to your machine in any case. I just watched the Go talk from Lang.NEXT and he uses Go's standard HTTP library and it made me a little jealous. Perhaps this would be a good candidate for Phobo's HTTP library. Regards, Brad Anderson --f46d040124ab5840fa04bdc7037a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sun, Apr 15, 2012 at 6:27 AM, goughy <span dir=3D"ltr"><<a href=3D"ma= ilto:goughy gmail.com">goughy gmail.com</a>></span> wrote:<br><div class= =3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8= ex;border-left:1px #ccc solid;padding-left:1ex"> Hi,<br> <br> I have just finished the first cut of an HTTP library to provide applicatio= n level support for HTTP (ie as a server, not a client). =A0The library pro= vide a very simple mechanism for processing HTTP requests both synchronousl= y (via delegates) and asynchronously (via std.concurrency) using request/re= sponse objects.<br> <br> eg.<br> <br> import std.stdio;<br> import protocol.http;<br> <br> int main( string[] args )<br> {<br> =A0 =A0httpServe( "127.0.0.1", 8888,<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(req) =3D> req.getResponse().<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0status( 200 ).<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0header( "Conte= nt-Type", "text/html" ).<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0content( "<= html><head></head><body><u></u>Processed ok</body&g= t;</html>" ) );<br> =A0 =A0return 0;<br> }<br> <br> The code is available on github: <a href=3D"https://github.com/goughy/d/tre= e/master/http4d" target=3D"_blank">https://github.com/goughy/d/<u></u>tree/= master/http4d</a><br> <br> Note that this is alpha quality code, so YMMV. =A0I would appreciate some f= eedback, critiques, opinions etc. - particularly in the area of it being &q= uot;idiomatic" as I'm still finding my feet in the D language.<br> <br> The good thing is without any real performance tuning, I can push through o= ver 23,000 requests per second, and I'm sure there is plenty of room fo= r improvement.<br> <br> Cheers.<br> <br> <br> </blockquote></div><br><div>Neat. =A0I like the integration with std.concur= rency and the API in general (though I too am still trying to get a feel fo= r idiomatic D). =A0How does 23,000 requests/sec compare to, say, nginx'= s performance (which seems to be the current performance king)? I just trie= d to look up some general performance figures but they are all over the pla= ce and don't correspond to your machine in any case.</div> <div><br></div><div>I just watched the Go talk from Lang.NEXT and he uses G= o's standard HTTP library and it made me a little jealous. Perhaps this= would be a good candidate for Phobo's HTTP library.</div><div><br> </div><div>Regards,</div><div>Brad Anderson</div> --f46d040124ab5840fa04bdc7037a--
Apr 16 2012
On Monday, 16 April 2012 at 07:46:11 UTC, Brad Anderson wrote:On Sun, Apr 15, 2012 at 6:27 AM, goughy <goughy gmail.com> wrote:Hi, I have just finished the first cut of an HTTP library to provide application level support for HTTP (ie as a server, not a client). The library provide a very simple mechanism for processing HTTP requests both synchronously (via delegates) and asynchronously (via std.concurrency) using request/response objects. eg. import std.stdio; import protocol.http; int main( string[] args ) { httpServe( "127.0.0.1", 8888, (req) => req.getResponse(). status( 200 ). header( "Content-Type", "text/html" ). content( "<html><head></head><body>**Processed ok</body></html>" ) ); return 0; } The code is available on github: https://github.com/goughy/d/** tree/master/http4d <https://github.com/goughy/d/tree/master/http4d> Note that this is alpha quality code, so YMMV. I would appreciate some feedback, critiques, opinions etc. - particularly in the area of it being "idiomatic" as I'm still finding my feet in the D language. The good thing is without any real performance tuning, I can push through over 23,000 requests per second, and I'm sure there is plenty of room for improvement. Cheers.
in general (though I too am still trying to get a feel for idiomatic D). How does 23,000 requests/sec compare to, say, nginx's performance (which seems to be the current performance king)? I just tried to look up some general performance figures but they are all over the place and don't correspond to your machine in any case. I just watched the Go talk from Lang.NEXT and he uses Go's standard HTTP library and it made me a little jealous. Perhaps this would be a good candidate for Phobo's HTTP library. Regards, Brad Anderson
I had a look at the following and thought 23k seemed pretty reasonable for a first cut: http://timyang.net/programming/c-erlang-java-performance/ But then I also saw http://nbonvin.wordpress.com/2011/03/14/apache-vs-nginx-vs-varnish-vs-gwan/, and G-WAN seems to be able to crack 120k, so this library is unlikely to hit that mark. But again there's benchmarks and benchmarks, and I haven't tuned any kernel params etc - just straight out of the box. There is some pretty naive code also that I'm sure could be better tuned, but it's currently more than enough for my planned uses, and I'm happy its in that range without, really, a huge amount of effort. I would be stoked if this was usable enough for Phobos, but the dependency on Zeromq might preclude that. Cheers.
Apr 16 2012









Brad Anderson <eco gnuk.net> 