|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Very slow throughput using socketsI'm tyring to develop a (very) basic web server, using yap-prolog but I
experience a very slow throughput using the socket functions. The following program is just an excerpt of a bigger program, but it experiences the same problem. It sends a small file (test.txt) about 40kb in size, regardless of the input query. To try it just create a text file called test.txt, about 40/50 kb in size, load the program in yap, open a browser and query http://127.0.0.1 I've tried it with different files, both text files than images (gif and png). In the console window you can see two messages, 'before' and 'after', issued just before and after the sending of the file. You will notice the delay. Then try with a bigger file (200/300 kb). The delay becomes intollerable. Any suggestion? Regards Maurizio. %----------------------------------------------------------------------% % global include % %----------------------------------------------------------------------% :- use_module(library(system)). :- use_module(library(lists)). :- use_module(library(charsio)). :- use_module(library(readutil)). :- set_prolog_flag(unknown,error). %----------------------------------------------------------------------% % i/o handling % %----------------------------------------------------------------------% send_message(Sout,Rcode,Contype,Message):- send_message_header(Sout,Rcode,Contype,"",Message). send_message_header(Sout,Rcode,Contype,Header,Message):- put_bytes("HTTP/1.0 ",Sout), put_bytes(Rcode,Sout), put_bytes("\r\n",Sout), put_bytes("Content-Type: ",Sout), put_bytes(Contype,Sout), put_bytes("\r\n",Sout), put_bytes(Header,Sout), code_len(Message,Size), put_bytes("Content-Length: ",Sout), put_bytes(Size,Sout), put_bytes("\r\n\r\n",Sout), put_bytes(Message,Sout). code_len(Message,Len):- length(Message,Size), number_codes(Size,Len). put_bytes([],_Sout). put_bytes([C|R],Sout):- put_byte(Sout,C), put_bytes(R,Sout). read_in_list(Name,List):- open(Name,read,S,[type(binary)]), read_stream_to_codes(S,List), close(S). send_file(Filename,Type,Sout):- read_in_list(Filename,L), write(before),nl, send_message(Sout,"200 OK",Type,L), write(after),nl. %----------------------------------------------------------------------% % main % %----------------------------------------------------------------------% :- initialization(go). go:- socket('AF_INET',Sock), socket_bind(Sock,'AF_INET'(_,80)), socket_listen(Sock,5), main_loop(Sock). main_loop(Sock) :- repeat, socket_accept(Sock,Sin), send_file('test.txt',"text/plain",Sin), flush_output(Sin), close(Sin), fail. ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ Yap-users mailing list Yap-users@... https://lists.sourceforge.net/lists/listinfo/yap-users |
|
|
Re: Very slow throughput using socketsHi Maurizio
I tried the experiment with an even larger file. YAP is really a bit slow, but that is mostly the overhead of sending byte by byte, which is very expensive. Otherwise, it just chugs along. Which OS are you using? Cheers Vitor On Wed, Apr 22, 2009 at 10:32 AM, Ferreira Maurizio <maurizio.ferreira@...> wrote: > I'm tyring to develop a (very) basic web server, using yap-prolog but I > experience a very slow throughput using the socket functions. The > following program is just an excerpt of a bigger program, but > it experiences the same problem. > It sends a small file (test.txt) about 40kb in size, regardless of the > input query. > > To try it just create a text file called test.txt, about 40/50 kb in > size, load the program in yap, open a browser and query http://127.0.0.1 > > I've tried it with different files, both text files than images (gif and > png). In the console window you can see two messages, 'before' and > 'after', issued just before and after the sending of the file. > You will notice the delay. > Then try with a bigger file (200/300 kb). > The delay becomes intollerable. > > > Any suggestion? > > Regards > Maurizio. > > %----------------------------------------------------------------------% > % global include % > %----------------------------------------------------------------------% > > :- use_module(library(system)). > :- use_module(library(lists)). > :- use_module(library(charsio)). > :- use_module(library(readutil)). > :- set_prolog_flag(unknown,error). > > %----------------------------------------------------------------------% > % i/o handling % > %----------------------------------------------------------------------% > > > > send_message(Sout,Rcode,Contype,Message):- > send_message_header(Sout,Rcode,Contype,"",Message). > > send_message_header(Sout,Rcode,Contype,Header,Message):- > put_bytes("HTTP/1.0 ",Sout), put_bytes(Rcode,Sout), > put_bytes("\r\n",Sout), > put_bytes("Content-Type: ",Sout), put_bytes(Contype,Sout), > put_bytes("\r\n",Sout), > put_bytes(Header,Sout), > code_len(Message,Size), > put_bytes("Content-Length: ",Sout), put_bytes(Size,Sout), > put_bytes("\r\n\r\n",Sout), > put_bytes(Message,Sout). > > code_len(Message,Len):- > length(Message,Size), > number_codes(Size,Len). > > put_bytes([],_Sout). > put_bytes([C|R],Sout):- put_byte(Sout,C), put_bytes(R,Sout). > > > read_in_list(Name,List):- > open(Name,read,S,[type(binary)]), > read_stream_to_codes(S,List), > close(S). > > send_file(Filename,Type,Sout):- > read_in_list(Filename,L), > write(before),nl, > send_message(Sout,"200 OK",Type,L), > write(after),nl. > > > > %----------------------------------------------------------------------% > % main % > %----------------------------------------------------------------------% > > :- initialization(go). > > > go:- > socket('AF_INET',Sock), > socket_bind(Sock,'AF_INET'(_,80)), > socket_listen(Sock,5), > main_loop(Sock). > > main_loop(Sock) :- > repeat, > socket_accept(Sock,Sin), > send_file('test.txt',"text/plain",Sin), > flush_output(Sin), > close(Sin), > fail. > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Yap-users mailing list > Yap-users@... > https://lists.sourceforge.net/lists/listinfo/yap-users > ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Yap-users mailing list Yap-users@... https://lists.sourceforge.net/lists/listinfo/yap-users |
|
|
Re: Very slow throughput using socketsA possibly naive question: SWI-Prolog has an excellent http library that makes web application development a breeze. Given that SWI and Yap are working together to increase compatibility (yay!!) how hard would it be to reuse the SWI library in Yap? On Apr 22, 2009, at 8:32 AM, Ferreira Maurizio wrote: > I'm tyring to develop a (very) basic web server, using yap-prolog > but I > experience a very slow throughput using the socket functions. The > following program is just an excerpt of a bigger program, but > it experiences the same problem. > It sends a small file (test.txt) about 40kb in size, regardless of the > input query. > > To try it just create a text file called test.txt, about 40/50 kb in > size, load the program in yap, open a browser and query http://127.0.0.1 > > I've tried it with different files, both text files than images (gif > and > png). In the console window you can see two messages, 'before' and > 'after', issued just before and after the sending of the file. > You will notice the delay. > Then try with a bigger file (200/300 kb). > The delay becomes intollerable. > > > Any suggestion? > > Regards > Maurizio. > > %----------------------------------------------------------------------% > % global > include % > %----------------------------------------------------------------------% > > :- use_module(library(system)). > :- use_module(library(lists)). > :- use_module(library(charsio)). > :- use_module(library(readutil)). > :- set_prolog_flag(unknown,error). > > %----------------------------------------------------------------------% > % i/o > handling % > %----------------------------------------------------------------------% > > > > send_message(Sout,Rcode,Contype,Message):- > send_message_header(Sout,Rcode,Contype,"",Message). > > send_message_header(Sout,Rcode,Contype,Header,Message):- > put_bytes("HTTP/1.0 ",Sout), put_bytes(Rcode,Sout), > put_bytes("\r\n",Sout), > put_bytes("Content-Type: ",Sout), put_bytes(Contype,Sout), > put_bytes("\r\n",Sout), > put_bytes(Header,Sout), > code_len(Message,Size), > put_bytes("Content-Length: ",Sout), put_bytes(Size,Sout), > put_bytes("\r\n\r\n",Sout), > put_bytes(Message,Sout). > > code_len(Message,Len):- > length(Message,Size), > number_codes(Size,Len). > > put_bytes([],_Sout). > put_bytes([C|R],Sout):- put_byte(Sout,C), put_bytes(R,Sout). > > > read_in_list(Name,List):- > open(Name,read,S,[type(binary)]), > read_stream_to_codes(S,List), > close(S). > > send_file(Filename,Type,Sout):- > read_in_list(Filename,L), > write(before),nl, > send_message(Sout,"200 OK",Type,L), > write(after),nl. > > > > %----------------------------------------------------------------------% > % > main % > %----------------------------------------------------------------------% > > :- initialization(go). > > > go:- > socket('AF_INET',Sock), > socket_bind(Sock,'AF_INET'(_,80)), > socket_listen(Sock,5), > main_loop(Sock). > > main_loop(Sock) :- > repeat, > socket_accept(Sock,Sin), > send_file('test.txt',"text/plain",Sin), > flush_output(Sin), > close(Sin), > fail. > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Yap-users mailing list > Yap-users@... > https://lists.sourceforge.net/lists/listinfo/yap-users > ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ Yap-users mailing list Yap-users@... https://lists.sourceforge.net/lists/listinfo/yap-users |
| Free embeddable forum powered by Nabble | Forum Help |