Thread: Re: [Cppcms-users] async_flush_output and multipart/x_mixed_replace
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-02-07 14:54:12
|
>> Slightly changed example that works (without boost::thread) > >Since the context is not thread safe, this makes sense. However, I already tried >your version without boost::thread and service::post in the first place. That's >why I left the two corresponding lines in my code as comments: > > [snip] > >Since you say it works this way, there must be something else which is >different. Could it have something to do with my web server or my browser? >I'm using nginx and Firefox, but tried Chrome as well. It is nginx. Small matrix of "working/not-working" (tested just now_ API \ Server Lighttpd Apache Nginx FastCGI Y N N SCGI Y Y N HTTP Y Y N (Can be fixed with buffering options) Nginx for some reason caches the response and do not try to froward it to the client ASAP. Which reminds me: http://blog.cppcms.com/post/99 >> >> http://cppcms.com/wikipp/en/page/thread_safety > >"[...] If asynchronous application or any other object that runs in the event >wants to execute some long running, blocking or heavy operation, it may do it by >submitting an execution handler to the thread pool. [...]" > >As I understand this, there's the Event Loop for asynchronous operations and >there's another Thread Pool for synchronous operations. In my case I have a >heavy computation, which I should send via service::post (is that right?) to the >Thread Pool. You you can post a job to thread pool using service().thread_pool().post(...) service().post(...) posts a job into event loop. > On the other side, I'd like to send back some progress or >intermediate computation results, which I can do only by using >context::async_flush_output, which is an asynchronous operation and thus part of >the Event Loop. So, is it possible at all to call asynchronous operations from >synchronous threads? Via service().post(...) Also note, if you have heavy computations you can always print intermediate results. For example: response().io_mode(cppcms::http::response::nogzip); for(int i=0;i<5;i++) { response().out() << "Test" << std::endl; booster::ptime::millisleep(1000); } This code does the same synchronously when application works on the thread pool it would work 100% (if you replace millisleep with your work) response().out() << std::flush flushes the data to the output. One thing you still must notice is disabling gzip compression otherwise it would be cached and would not work 1-to-1. By default gzip is enabled and browsers by default accept gzip compressed data, so it is important to disable so the std::flush would work (std::endl calls std::flush) Regards, Artyom Beilis |
From: Tobias R. <rei...@go...> - 2012-02-08 14:54:48
|
Artyom Beilis <artyomtnk@...> writes: > Small matrix of "working/not-working" (tested just now_ > > API \ Server Lighttpd Apache Nginx > FastCGI Y N N > SCGI Y Y N > HTTP Y Y N (Can be fixed with buffering options) > > Nginx for some reason caches the response and do not try > to froward it to the client ASAP. You are right. You can turn off buffering in proxy mode but not in fastcgi mode. That's .... no words! So it's either sending packages at least as big as the buffer size (which I can't set less than 1k), or moving to lighttpd. Hm, easy question. > Also note, if you have heavy computations you can always print intermediate results. > > For example: > > response().io_mode(cppcms::http::response::nogzip); > for(int i=0;i<5;i++) { > response().out() << "Test" << std::endl; > booster::ptime::millisleep(1000); > } That's what I was up to. Thank you. Thanks again for your time and your help. I do appreciate. Best regards, Tobias |
From: Sergei <ser...@gm...> - 2013-10-24 17:06:45
|
FastCGI buffering option is fixed. fastcgi_buffering off; http://trac.nginx.org/nginx/ticket/159 |
From: Artyom B. <art...@ya...> - 2013-10-24 19:27:25
|
Thanks... Good to know. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ -------------------------------------------- On Thu, 10/24/13, Sergei <ser...@gm...> wrote: Subject: Re: [Cppcms-users] async_flush_output and multipart/x_mixed_replace To: cpp...@li... Date: Thursday, October 24, 2013, 7:06 PM FastCGI buffering option is fixed. fastcgi_buffering off; http://trac.nginx.org/nginx/ticket/159 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk _______________________________________________ Cppcms-users mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppcms-users |