From: Tobias O. <tob...@gm...> - 2007-02-12 01:22:17
Attachments:
testcomet.tar.gz
|
I've hacked some kind of minimal Comet JS tag streaming test (attached), which works as intended. However, actually, I don't fully understand _why_ it works, and thus I'm a little bit unsettled if it would work under all circumstances. I got a Yaws page with a single <erl> block containing s.th. like this: out(Arg) -> spawn(.., Arg#arg.pid, ..), {streamcontent, "text/html", "<html><body>", infinity}. Now the spawned process _immediately_ does a yaws_api:stream_chunk_deliver(..) to the Yaws worker process. But out/1 will only trigger the Yaws internal machinery for setting up the stream when it returns? So it could happen that my spawned process tries to deliver a "chunk" on a stream that isn't setup yet? Why does it work then? Process spawn latency? Thus, mere luck? What would be the "correct" code? Having 2 <erl> blocks, the first starting the stream, and the second spawning the process that sents chunks to the Yaws worker? Thx, Tobias |
From: <ju...@pr...> - 2007-02-13 03:28:55
|
I think you don't need to be unsettled about that. An Erlang process doesn't need to be in a 'receive' loop before you send a message to it, so it's ok if the {streamcontent, Data} message sent by yaws_api:stream_chunk_deliver/2 somehow arrives before yaws_server goes into it's stream_loop_send - the message will wait and be processed as soon as the receive is run. Try this in an erl shell: >self() ! {blah, etc}. {blah, etc} >receive {blah, etc} -> got_it after 1000 -> timed_out end. got_it Julian ----- Original Message ----- From: "Tobias Oberstein" <tob...@gm...> To: <erl...@li...> Sent: Monday, February 12, 2007 1:22 AM Subject: [Erlyaws-list] Comet test and Yaws streaming Q again .. > I've hacked some kind of minimal Comet JS tag streaming test (attached), > which works as intended. > > However, actually, I don't fully understand _why_ it works, and thus > I'm a little bit unsettled if it would work under all circumstances. > > > I got a Yaws page with a single <erl> block containing s.th. like this: > > > out(Arg) -> > spawn(.., Arg#arg.pid, ..), > {streamcontent, "text/html", "<html><body>", infinity}. > > > Now the spawned process _immediately_ does a > > > yaws_api:stream_chunk_deliver(..) > > > to the Yaws worker process. > > But out/1 will only trigger the Yaws internal machinery for setting up > the stream when it returns? > > So it could happen that my spawned process tries to deliver a "chunk" > on a stream that isn't setup yet? > > Why does it work then? Process spawn latency? Thus, mere luck? > > What would be the "correct" code? > > Having 2 <erl> blocks, the first starting the stream, and the second > spawning the process that sents chunks to the Yaws worker? > > Thx, > Tobias > ---------------------------------------------------------------------------- ---- > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 ---------------------------------------------------------------------------- ---- > _______________________________________________ > Erlyaws-list mailing list > Erl...@li... > https://lists.sourceforge.net/lists/listinfo/erlyaws-list > |
From: Tobias O. <tob...@gm...> - 2007-02-13 21:51:12
|
ju...@pr... schrieb: > I think you don't need to be unsettled about that. > An Erlang process doesn't need to be in a 'receive' loop before you send a > message to it, so it's ok if the ok, understood. so the msg will not be lost .. > {streamcontent, Data} message sent by yaws_api:stream_chunk_deliver/2 > somehow arrives before yaws_server goes into it's > stream_loop_send - the message will wait and be processed as soon as the > receive is run. msgs will not be lost, but queued in msg inbox of the Yaws worker? what about msg order? I did: >> out(Arg) -> >> spawn(.., Arg#arg.pid, ..), >> {streamcontent, "text/html", "<html><body>", infinity}. and the spawned process sends immediately (for sake of simplicity) "<h1>bla,bla</h1>" by calling yaws_api:stream_chunk_deliver(..) then out/1 will return and send "<html><body>" so the messages in the Yaws worker msg inbox would be msg 1: {streamcontent, "<h1>bla,bla</h1>"} msg 2: {streamcontent, "<html><body>"} right? but then, when actual msg processing starts in "stream_loop_send", the first msg in inbox matching some receive clause will fire off? I can see no difference in the msgs as they arrive at "stream_loop_send" between msgs sent via yaws_api:stream_chunk_deliver versus the msg that will be generated from the return value of out/1 via -- yaws_server.erl -- handle_out_reply({streamcontent, MimeType, First}, _LineNo,_YawsFile, _UT, _A) -> yaws:outh_set_content_type(MimeType), {streamcontent, MimeType, First}; -- thus the client should receive: <h1>bla,bla</h1> <html><body> ... ?? but I see <html><body> <h1>bla,bla</h1> ... which of course is good, but why does it happen to become real? Would you give it another try explaining? thx alot, Tobias > > Try this in an erl shell: > >> self() ! {blah, etc}. > {blah, etc} > >> receive {blah, etc} -> got_it after 1000 -> timed_out end. > got_it > > > Julian > > ----- Original Message ----- > From: "Tobias Oberstein" <tob...@gm...> > To: <erl...@li...> > Sent: Monday, February 12, 2007 1:22 AM > Subject: [Erlyaws-list] Comet test and Yaws streaming Q again .. > > >> I've hacked some kind of minimal Comet JS tag streaming test (attached), >> which works as intended. >> >> However, actually, I don't fully understand _why_ it works, and thus >> I'm a little bit unsettled if it would work under all circumstances. >> >> >> I got a Yaws page with a single <erl> block containing s.th. like this: >> >> >> out(Arg) -> >> spawn(.., Arg#arg.pid, ..), >> {streamcontent, "text/html", "<html><body>", infinity}. >> >> >> Now the spawned process _immediately_ does a >> >> >> yaws_api:stream_chunk_deliver(..) >> >> >> to the Yaws worker process. >> >> But out/1 will only trigger the Yaws internal machinery for setting up >> the stream when it returns? >> >> So it could happen that my spawned process tries to deliver a "chunk" >> on a stream that isn't setup yet? >> >> Why does it work then? Process spawn latency? Thus, mere luck? >> >> What would be the "correct" code? >> >> Having 2 <erl> blocks, the first starting the stream, and the second >> spawning the process that sents chunks to the Yaws worker? >> >> Thx, >> Tobias >> > > > ---------------------------------------------------------------------------- > ---- > > >> ------------------------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, security? >> Get stuff done quickly with pre-integrated technology to make your job > easier. >> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > ---------------------------------------------------------------------------- > ---- > > >> _______________________________________________ >> Erlyaws-list mailing list >> Erl...@li... >> https://lists.sourceforge.net/lists/listinfo/erlyaws-list >> > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Erlyaws-list mailing list > Erl...@li... > https://lists.sourceforge.net/lists/listinfo/erlyaws-list > > |
From: <ju...@pr...> - 2007-02-14 00:41:18
|
> I can see no difference in the msgs as they arrive at "stream_loop_send" > between msgs sent via yaws_api:stream_chunk_deliver versus the msg that > will be generated from the return value of out/1 via There is a big difference - in that the return value of out/1 is not sent as an erlang 'message' at all :) The initial chunk of data is sent by the Yaws worker before it enters the receive loop 'stream_loop_send' to get the rest of the chunks. Notice in the snippet below from deliver_dyn_part/8, where the FirstChunk is accumulated and delivered. {streamcontent, MimeType, FirstChunk} -> yaws:outh_set_content_type(MimeType), accumulate_content(FirstChunk), Priv = deliver_accumulated(Arg, CliSock, decide, undefined, stream), stream_loop_send(Priv, CliSock); In short, I think that in this case there's no way you could get your data delivered out-of-order. Julian ----- Original Message ----- From: "Tobias Oberstein" <tob...@gm...> To: <ju...@pr...> Cc: <erl...@li...> Sent: Tuesday, February 13, 2007 9:51 PM Subject: Re: [Erlyaws-list] Comet test and Yaws streaming Q again .. > ju...@pr... schrieb: > > I think you don't need to be unsettled about that. > > An Erlang process doesn't need to be in a 'receive' loop before you send a > > message to it, so it's ok if the > > ok, understood. so the msg will not be lost .. > > > {streamcontent, Data} message sent by yaws_api:stream_chunk_deliver/2 > > somehow arrives before yaws_server goes into it's > > stream_loop_send - the message will wait and be processed as soon as the > > receive is run. > > msgs will not be lost, but queued in msg inbox of the Yaws worker? > > what about msg order? > > I did: > > >> out(Arg) -> > >> spawn(.., Arg#arg.pid, ..), > >> {streamcontent, "text/html", "<html><body>", infinity}. > > and the spawned process sends immediately (for sake of simplicity) > > "<h1>bla,bla</h1>" > > by calling yaws_api:stream_chunk_deliver(..) > > then out/1 will return and send > > "<html><body>" > > so the messages in the Yaws worker msg inbox would be > > msg 1: {streamcontent, "<h1>bla,bla</h1>"} > msg 2: {streamcontent, "<html><body>"} > > right? > > but then, when actual msg processing starts in "stream_loop_send", > the first msg in inbox matching some receive clause will fire off? > > I can see no difference in the msgs as they arrive at "stream_loop_send" > between msgs sent via yaws_api:stream_chunk_deliver versus the msg that > will be generated from the return value of out/1 via > > -- yaws_server.erl -- > handle_out_reply({streamcontent, MimeType, First}, > _LineNo,_YawsFile, _UT, _A) -> > yaws:outh_set_content_type(MimeType), > {streamcontent, MimeType, First}; > -- > > thus the client should receive: > > <h1>bla,bla</h1> > <html><body> > ... > > ?? > > but I see > > <html><body> > <h1>bla,bla</h1> > ... > > which of course is good, but why does it happen to become real? > > Would you give it another try explaining? > > thx alot, > Tobias > |