Re: D simple web server

2013-09-10 Thread gedaiu

Hi,

I added websocket support to the server.

This is the link to the git repo:
https://github.com/gedaiu/DSWS

Thanks,
Bogdan


Re: D simple web server

2013-09-03 Thread gedaiu

Thanks for reply,

@Adam D. Ruppe I ignored your collection of tools but is not very 
good documented...


@Rémy Mouëza When I started my project, I wanted to use mongoose 
but there where no bindings for D at that time, so I decided to 
use a simpler web server, libmicrohttpd, but it was not the best 
solution because my server where crashing all the time, so I 
decided to create one from scratch in D.


I made an update to the code and I added the option to initialize 
the terver using delegates.


Thanks,
Bogdan




On Saturday, 31 August 2013 at 18:44:47 UTC, Rémy Mouëza wrote:

Your code seems rather nice.

That said, here are some remarks of a purely stylistic nature 
:-) :


- You can use foreach instead of for to simplify your loop 
statements over arrays and other collections:

auto array = [1, 2, 3];
foreach (item; array) {
writeln (item);
}

  foreach can also support indexed iteration of your items:
auto array = [a, b, c];
foreach (index, item; array) {
writefln (%d: %s, index, item);
}

  and if you just want to iterate a certain amount of time, you 
can use ranges:

foreach (index; 1..100) {
writeln (index);
}

- You don't have to put each class in a different file: you 
still can do if you prefer it that way.


- I tend to prefer to have class members of same visibility 
grouped together under a public:, protected: or private: 
block, either using the colon or the braces instead of always 
specifying the visibility - this kind of help me better 
understand what will be useful when using the class.


- Associative arrays can be initialized with literals, so 
instead of having lots of:

   status_message[100] = Continue;
   status_message[101] = ...
   ...
   status_message[505] = HTTP Version not supported;

 you can use:
   status_message = [
   100: Continue,
   101: ...
   505: HTTP Version not supported
   ];

 which I find more concise.

- You can also use unified function calls:
  instead of: to!string(port)
  you can do: port.to!string
  the latter having a more English feel when reading.

Again, these are purely stylistic considerations, D's 
flexibility allows you to choose from many styles.



On a design standpoint, I would have preferred a delegate for 
the processRequest() method instead of requiring the users to 
derive from the WebServer class - on second thought, that may 
too be a stylistic issue :-) .



Also related: I have started to write some high level bindings 
to the Mongoose embedded webserver library, written in C (using 
Jacob Carlsberg's dstep for the low level bindings). The source 
code is available here: 
https://github.com/remy-j-a-moueza/mongooseD .
You may find some stuff to reuse or get inspiration from for 
your server.


Adam Ruppe also has a lot of interesting tools beyond the basic 
web serving that you may get interested in 
(https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff).




On 08/31/2013 06:42 PM, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web 
server, and I
couldn't find one implemented in D(excepting vibe.d), I 
started to
implement some web server classes in D with the hope that my 
work will
be useful to someone else as well. If you are interested in 
this
project, or if you want to contribute to it, here is the link 
to the git

repository:

https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if
someone would like to spare some time for a code review for my 
work.


Thanks,
Bogdan




Re: D simple web server

2013-09-03 Thread Craig Dillabaugh

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web server, 
and I couldn't find one implemented in D(excepting vibe.d), I 
started to implement some web server classes in D with the hope 
that my work will be useful to someone else as well. If you are 
interested in this project, or if you want to contribute to it, 
here is the link to the git repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a code 
review for my work.


Thanks,
Bogdan


Just curious to know, why vibe.d wasn't an option for you?

Craig


Re: D simple web server

2013-09-03 Thread gedaiu
I belive the fails are from the writeln. I made a commit where i 
removed them.  Please update the code


thanks
Bogdan


On Tuesday, 3 September 2013 at 15:49:44 UTC, Batuhan Göksu wrote:

On Tuesday, 3 September 2013 at 15:23:36 UTC, gedaiu wrote:

Hi,

nice test!

on my computer(linux, i5, 8gb ram) i have these results:

siege -d10 -c50 -t 133s http://localhost:8080/

Transactions:   1290 hits
Availability: 100.00 %
Elapsed time: 132.70 secs
Data transferred:   0.01 MB
Response time:  0.14 secs
Transaction rate:   9.72 trans/sec
Throughput: 0.00 MB/sec
Concurrency:1.35
Successful transactions:1290
Failed transactions:   0
Longest transaction:   11.42
Shortest transaction:   0.00


and apache on the same machine has these results:

siege -d10 -c50 -t 133s http://localhost/

Transactions:   1269 hits
Availability: 100.00 %
Elapsed time: 132.63 secs
Data transferred:   0.32 MB
Response time:  0.09 secs
Transaction rate:   9.57 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.91
Successful transactions:1269
Failed transactions:   0
Longest transaction:0.43
Shortest transaction:   0.05

Thanks,
Bogdan

On Tuesday, 3 September 2013 at 14:56:33 UTC, Batuhan Göksu 
wrote:

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web 
server, and I couldn't find one implemented in D(excepting 
vibe.d), I started to implement some web server classes in D 
with the hope that my work will be useful to someone else as 
well. If you are interested in this project, or if you want 
to contribute to it, here is the link to the git repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a 
code review for my work.


Thanks,
Bogdan


But got a nice progression of application development.

HTTP stress test done with Siege.

Siege Code : siege -d10 -c50 http://localhost/

Transactions:156 hits
Availability:  12.69 %
Elapsed time: 133.23 secs
Data transferred:   0.18 MB
Response time:  0.07 secs
Transaction rate:   1.17 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.08
Successful transactions:156
Failed transactions:1073
Longest transaction:0.33
Shortest transaction:   0.00



There's something wrong with these results.
I did it again while writing this post here are the results

Siege Code : siege -d10 -c50 http://localhost/

These results have been on the front side with Nginx (ProxyPass)

Please try this way. (Siege Code: http://localhost/ 
siege-d10-c50)


Last Results
--
Transactions:187 hits
Availability:  14.84 %
Elapsed time: 133.49 secs
Data transferred:   0.18 MB
Response time:  0.10 secs
Transaction rate:   1.40 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.14
Successful transactions: 187
Failed transactions:1073
Longest transaction:0.61
Shortest transaction:   0.00




Re: D simple web server

2013-09-03 Thread gedaiu

Hi,

nice test!

on my computer(linux, i5, 8gb ram) i have these results:

siege -d10 -c50 -t 133s http://localhost:8080/

Transactions:   1290 hits
Availability: 100.00 %
Elapsed time: 132.70 secs
Data transferred:   0.01 MB
Response time:  0.14 secs
Transaction rate:   9.72 trans/sec
Throughput: 0.00 MB/sec
Concurrency:1.35
Successful transactions:1290
Failed transactions:   0
Longest transaction:   11.42
Shortest transaction:   0.00


and apache on the same machine has these results:

siege -d10 -c50 -t 133s http://localhost/

Transactions:   1269 hits
Availability: 100.00 %
Elapsed time: 132.63 secs
Data transferred:   0.32 MB
Response time:  0.09 secs
Transaction rate:   9.57 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.91
Successful transactions:1269
Failed transactions:   0
Longest transaction:0.43
Shortest transaction:   0.05

Thanks,
Bogdan

On Tuesday, 3 September 2013 at 14:56:33 UTC, Batuhan Göksu wrote:

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web 
server, and I couldn't find one implemented in D(excepting 
vibe.d), I started to implement some web server classes in D 
with the hope that my work will be useful to someone else as 
well. If you are interested in this project, or if you want to 
contribute to it, here is the link to the git repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a code 
review for my work.


Thanks,
Bogdan


But got a nice progression of application development.

HTTP stress test done with Siege.

Siege Code : siege -d10 -c50 http://localhost/

Transactions:156 hits
Availability:  12.69 %
Elapsed time: 133.23 secs
Data transferred:   0.18 MB
Response time:  0.07 secs
Transaction rate:   1.17 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.08
Successful transactions:156
Failed transactions:1073
Longest transaction:0.33
Shortest transaction:   0.00




Re: D simple web server

2013-09-03 Thread gedaiu
I did nt made it to run it as a library... And it's a project to 
big for what I need... or maybe I am wrong... i'm a noobie with D.


Thanks,
Bogdan

On Tuesday, 3 September 2013 at 15:15:03 UTC, Craig Dillabaugh 
wrote:

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web 
server, and I couldn't find one implemented in D(excepting 
vibe.d), I started to implement some web server classes in D 
with the hope that my work will be useful to someone else as 
well. If you are interested in this project, or if you want to 
contribute to it, here is the link to the git repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a code 
review for my work.


Thanks,
Bogdan


Just curious to know, why vibe.d wasn't an option for you?

Craig




Re: D simple web server

2013-09-03 Thread Craig Dillabaugh

On Tuesday, 3 September 2013 at 15:27:34 UTC, gedaiu wrote:
I did nt made it to run it as a library... And it's a project 
to big for what I need... or maybe I am wrong... i'm a noobie 
with D.


Thanks,
Bogdan

On Tuesday, 3 September 2013 at 15:15:03 UTC, Craig Dillabaugh 
wrote:

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web 
server, and I couldn't find one implemented in D(excepting 
vibe.d), I started to implement some web server classes in D 
with the hope that my work will be useful to someone else as 
well. If you are interested in this project, or if you want 
to contribute to it, here is the link to the git repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a code 
review for my work.


Thanks,
Bogdan


Just curious to know, why vibe.d wasn't an option for you?

Craig


That make sense. I am experimenting with vibe.d and I was curious
if there were some technical limitations that stopped you from
using it.

Good luck with your project. I am a bit busy, but I perhaps I
will have a chance to try it out.

Craig




Re: D simple web server

2013-09-03 Thread Batuhan Göksu

On Tuesday, 3 September 2013 at 15:55:48 UTC, gedaiu wrote:
I belive the fails are from the writeln. I made a commit where 
i removed them.  Please update the code


thanks
Bogdan


On Tuesday, 3 September 2013 at 15:49:44 UTC, Batuhan Göksu 
wrote:

On Tuesday, 3 September 2013 at 15:23:36 UTC, gedaiu wrote:

Hi,

nice test!

on my computer(linux, i5, 8gb ram) i have these results:

siege -d10 -c50 -t 133s http://localhost:8080/

Transactions:   1290 hits
Availability: 100.00 %
Elapsed time: 132.70 secs
Data transferred:   0.01 MB
Response time:  0.14 secs
Transaction rate:   9.72 trans/sec
Throughput: 0.00 MB/sec
Concurrency:1.35
Successful transactions:1290
Failed transactions:   0
Longest transaction:   11.42
Shortest transaction:   0.00


and apache on the same machine has these results:

siege -d10 -c50 -t 133s http://localhost/

Transactions:   1269 hits
Availability: 100.00 %
Elapsed time: 132.63 secs
Data transferred:   0.32 MB
Response time:  0.09 secs
Transaction rate:   9.57 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.91
Successful transactions:1269
Failed transactions:   0
Longest transaction:0.43
Shortest transaction:   0.05

Thanks,
Bogdan

On Tuesday, 3 September 2013 at 14:56:33 UTC, Batuhan Göksu 
wrote:

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web 
server, and I couldn't find one implemented in D(excepting 
vibe.d), I started to implement some web server classes in 
D with the hope that my work will be useful to someone else 
as well. If you are interested in this project, or if you 
want to contribute to it, here is the link to the git 
repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a 
code review for my work.


Thanks,
Bogdan


But got a nice progression of application development.

HTTP stress test done with Siege.

Siege Code : siege -d10 -c50 http://localhost/

Transactions:156 hits
Availability:  12.69 %
Elapsed time: 133.23 secs
Data transferred:   0.18 MB
Response time:  0.07 secs
Transaction rate:   1.17 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.08
Successful transactions:156
Failed transactions:1073
Longest transaction:0.33
Shortest transaction:   0.00



There's something wrong with these results.
I did it again while writing this post here are the results

Siege Code : siege -d10 -c50 http://localhost/

These results have been on the front side with Nginx 
(ProxyPass)


Please try this way. (Siege Code: http://localhost/ 
siege-d10-c50)


Last Results
--
Transactions:187 hits
Availability:  14.84 %
Elapsed time: 133.49 secs
Data transferred:   0.18 MB
Response time:  0.10 secs
Transaction rate:   1.40 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.14
Successful transactions: 187
Failed transactions:1073
Longest transaction:0.61
Shortest transaction:   0.00


Is now running.

The only problem 172 bytes when it comes to data is collapsing.

HTTP/1.1 502 1.22 secs: 172 bytes == GET /


Re: D simple web server

2013-09-03 Thread gedaiu

On Tuesday, 3 September 2013 at 18:49:25 UTC, Batuhan Göksu wrote:

On Tuesday, 3 September 2013 at 15:55:48 UTC, gedaiu wrote:
I belive the fails are from the writeln. I made a commit where 
i removed them.  Please update the code


thanks
Bogdan


On Tuesday, 3 September 2013 at 15:49:44 UTC, Batuhan Göksu 
wrote:

On Tuesday, 3 September 2013 at 15:23:36 UTC, gedaiu wrote:

Hi,

nice test!

on my computer(linux, i5, 8gb ram) i have these results:

siege -d10 -c50 -t 133s http://localhost:8080/

Transactions:   1290 hits
Availability: 100.00 %
Elapsed time: 132.70 secs
Data transferred:   0.01 MB
Response time:  0.14 secs
Transaction rate:   9.72 trans/sec
Throughput: 0.00 MB/sec
Concurrency:1.35
Successful transactions:1290
Failed transactions:   0
Longest transaction:   11.42
Shortest transaction:   0.00


and apache on the same machine has these results:

siege -d10 -c50 -t 133s http://localhost/

Transactions:   1269 hits
Availability: 100.00 %
Elapsed time: 132.63 secs
Data transferred:   0.32 MB
Response time:  0.09 secs
Transaction rate:   9.57 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.91
Successful transactions:1269
Failed transactions:   0
Longest transaction:0.43
Shortest transaction:   0.05

Thanks,
Bogdan

On Tuesday, 3 September 2013 at 14:56:33 UTC, Batuhan Göksu 
wrote:

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web 
server, and I couldn't find one implemented in D(excepting 
vibe.d), I started to implement some web server classes in 
D with the hope that my work will be useful to someone 
else as well. If you are interested in this project, or if 
you want to contribute to it, here is the link to the git 
repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a 
code review for my work.


Thanks,
Bogdan


But got a nice progression of application development.

HTTP stress test done with Siege.

Siege Code : siege -d10 -c50 http://localhost/

Transactions:156 hits
Availability:  12.69 %
Elapsed time: 133.23 secs
Data transferred:   0.18 MB
Response time:  0.07 secs
Transaction rate:   1.17 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.08
Successful transactions:156
Failed transactions:1073
Longest transaction:0.33
Shortest transaction:   0.00



There's something wrong with these results.
I did it again while writing this post here are the results

Siege Code : siege -d10 -c50 http://localhost/

These results have been on the front side with Nginx 
(ProxyPass)


Please try this way. (Siege Code: http://localhost/ 
siege-d10-c50)


Last Results
--
Transactions:187 hits
Availability:  14.84 %
Elapsed time: 133.49 secs
Data transferred:   0.18 MB
Response time:  0.10 secs
Transaction rate:   1.40 trans/sec
Throughput: 0.00 MB/sec
Concurrency:0.14
Successful transactions: 187
Failed transactions:1073
Longest transaction:0.61
Shortest transaction:   0.00


Is now running.

The only problem 172 bytes when it comes to data is 
collapsing.


HTTP/1.1 502 1.22 secs: 172 bytes == GET /


Sorry... but I don't think I understand what you want to say... 
can you give more information about it?


Thanks,
Bogdan


D simple web server

2013-08-31 Thread gedaiu

Hi,

Because I have a personal project based on a custom web server, 
and I couldn't find one implemented in D(excepting vibe.d), I 
started to implement some web server classes in D with the hope 
that my work will be useful to someone else as well. If you are 
interested in this project, or if you want to contribute to it, 
here is the link to the git repository:


https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would 
apreciate if someone would like to spare some time for a code 
review for my work.


Thanks,
Bogdan


Re: D simple web server

2013-08-31 Thread Adam D. Ruppe

On Saturday, 31 August 2013 at 16:42:11 UTC, gedaiu wrote:
Because I have a personal project based on a custom web server, 
and I couldn't find one implemented in D(excepting vibe.d)


My cgi.d has one too:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/cgi.d

===
void hello(Cgi cgi) { cgi.write(hello); }
mixin GenericMain!hello;
===

dmd test.d cgi.d -version=embedded_httpd

Then run test and it listens on port 8085 by default, and you can 
change that with a command line argument --port 3000 for example.


Re: D simple web server

2013-08-31 Thread Rémy Mouëza

Your code seems rather nice.

That said, here are some remarks of a purely stylistic nature :-) :

- You can use foreach instead of for to simplify your loop 
statements over arrays and other collections:

auto array = [1, 2, 3];
foreach (item; array) {
writeln (item);
}

  foreach can also support indexed iteration of your items:
auto array = [a, b, c];
foreach (index, item; array) {
writefln (%d: %s, index, item);
}

  and if you just want to iterate a certain amount of time, you can use 
ranges:

foreach (index; 1..100) {
writeln (index);
}

- You don't have to put each class in a different file: you still can do 
if you prefer it that way.


- I tend to prefer to have class members of same visibility grouped 
together under a public:, protected: or private: block, either 
using the colon or the braces instead of always specifying the 
visibility - this kind of help me better understand what will be useful 
when using the class.


- Associative arrays can be initialized with literals, so instead of 
having lots of:

   status_message[100] = Continue;
   status_message[101] = ...
   ...
   status_message[505] = HTTP Version not supported;

 you can use:
   status_message = [
   100: Continue,
   101: ...
   505: HTTP Version not supported
   ];

 which I find more concise.

- You can also use unified function calls:
  instead of: to!string(port)
  you can do: port.to!string
  the latter having a more English feel when reading.

Again, these are purely stylistic considerations, D's flexibility allows 
you to choose from many styles.



On a design standpoint, I would have preferred a delegate for the 
processRequest() method instead of requiring the users to derive from 
the WebServer class - on second thought, that may too be a stylistic 
issue :-) .



Also related: I have started to write some high level bindings to the 
Mongoose embedded webserver library, written in C (using Jacob 
Carlsberg's dstep for the low level bindings). The source code is 
available here: https://github.com/remy-j-a-moueza/mongooseD .

You may find some stuff to reuse or get inspiration from for your server.

Adam Ruppe also has a lot of interesting tools beyond the basic web 
serving that you may get interested in 
(https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff). 




On 08/31/2013 06:42 PM, gedaiu wrote:

Hi,

Because I have a personal project based on a custom web server, and I
couldn't find one implemented in D(excepting vibe.d), I started to
implement some web server classes in D with the hope that my work will
be useful to someone else as well. If you are interested in this
project, or if you want to contribute to it, here is the link to the git
repository:

https://github.com/gedaiu/DSWS

Also, I don't have a lot of experience with D and I would apreciate if
someone would like to spare some time for a code review for my work.

Thanks,
Bogdan