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 |