Thread: [Cppcms-users] Multiple class of render()
Brought to you by:
artyom-beilis
From: Christian G. <chr...@gm...> - 2012-06-20 14:35:13
|
Hi all, I found an interesting jquery lib, which speeds up page switching a lot. This seems to solve my performance problems I have on my embedded device. Have a loot at it: https://github.com/defunkt/jquery-pjax I have replaced all calls of render with ajax_render, which looks like: void Base::ajax_render(std::string template_name, cppcms::base_content &content) { bool chromeless = false; if (request().getenv("HTTP_X_PJAX") == "true") { chromeless = true; } BOOSTER_DEBUG("ajax_render") << "chromeless: " << chromeless; if (chromeless) { render(template_name, content); } else { static content::master m; render("header", m); render(template_name, content); // as a template for footer is an overkill, we do it here response().out() << " </div>\n"; response().out() << "</body>\n"; response().out() << "</html>\n"; } } Is the usage of multiple render class the best solution? thanks -- Christian Gmeiner, MSc |
From: <ele...@ex...> - 2012-06-20 23:36:47
|
> > Is the usage of multiple render class the best solution? > Im not sure what youre trying to accomplish, but cant you solve that with template inheritance instead of multiple render function? Did you look at returning JSON instead of HTML? I mean, it kind of makes ajax useless if you are returning HTML with AJAX as the whole point of AJAX is to diminish network traffic. Im not sure about the static qualifier of the content object though. Artyom might have to answer this but i didnt think cppcms::base_content is thread safe. So you should make sure you arent modifying it anywhere. |
From: Christian G. <chr...@gm...> - 2012-06-21 06:31:10
|
> >> >> Is the usage of multiple render class the best solution? >> > > Im not sure what youre trying to accomplish, but cant you solve that with > template inheritance instead of multiple render function? Did you look at > returning JSON instead of HTML? I mean, it kind of makes ajax useless if > you are returning HTML with AJAX as the whole point of AJAX is to diminish > network traffic. > The main problem for my application is the response time if a page change should be done. So in order to improve this situation I only want/need to replace a div DOM object with the loaded content. In general an easy task, but this only works if the whole page gets loaded once. This saves loading of the big main js and css files every time (including parsing etc). A quite good tutorial about pjax can be found here: http://blog.ntotten.com/2012/04/09/building-super-fast-web-apps-with-pjax/ > > Im not sure about the static qualifier of the content object though. > Artyom might have to answer this but i didnt think cppcms::base_content is > thread safe. So you should make sure you arent modifying it anywhere. > Maybe there is an other way of doing it.. may Artyom has an idea. -- Christian Gmeiner, MSc |
From: <ele...@ex...> - 2012-06-21 07:36:37
|
> The main problem for my application is the response time if a page change > should > be done. So in order to improve this situation I only want/need to replace > a div > DOM object with the loaded content. In general an easy task, but this only > works > if the whole page gets loaded once. This saves loading of the big main > js and css files > every time (including parsing etc). Ok, but shouldn't the JS/CSS be cached on the client anyway? Have you considered using the built-in 2 level cache? Petr |
From: Christian G. <chr...@gm...> - 2012-06-21 08:36:38
|
2012/6/21 <ele...@ex...>: >> The main problem for my application is the response time if a page change >> should >> be done. So in order to improve this situation I only want/need to replace >> a div >> DOM object with the loaded content. In general an easy task, but this only >> works >> if the whole page gets loaded once. This saves loading of the big main >> js and css files >> every time (including parsing etc). > > Ok, but shouldn't the JS/CSS be cached on the client anyway? > It should, but dont ask me what chrome is doing in the end. > Have you considered using the built-in 2 level cache? The lowest target device for the software under development is an AMD Geode LX with 500 MHz and 512 MB RAM. The cppcms application and chrome are running on the same device. Without this "Ajax replacing of DOM-container" a page change takes 2-3 seconds, but it this ajax stuff it takes less then 1 second. The page change must be as fast as possible, else it is a problem for our user interaction. Also I need to support different screen resolutions (qvga and vga) - done via html body id and css. So I don't see that much sense in caching so dynamic pages, but may I be wrong :) -- Christian Gmeiner, MSc |
From: <ele...@ex...> - 2012-06-21 08:51:30
|
>> Ok, but shouldn't the JS/CSS be cached on the client anyway? >> > It should, but dont ask me what chrome is doing in the end. Are you running the application from the built in http server? Or are you using fastcgi/nginx ? I believe the built in http server sends only minimal headers. It doesn't send Last Modified or any other caching headers. It got me by surprise also. But it makes sense. During development you're unlikely need any caching at all and thats what the built in http server was designed for. > Also I need to support different screen resolutions (qvga and vga) - > done via html > body id and css. So I don't see that much sense in caching so dynamic > pages, but > may I be wrong :) Well I never had to do this but, if the above works for you (the CSS/JS caching). With the cppcms cache you're caching the content. Provided that: 1) You can cache JS/CSS files in chrome 2) Most of your JS/CSS is is not inline with HTML 3) The rest you can cache on the server side I think you shouldn't need PJAX at all. Judging by the difference in speed you get due to not loading JS/CSS on every page load, that is likely your bottleneck. Petr |
From: Christian G. <chr...@gm...> - 2012-06-21 09:05:46
|
>>> Ok, but shouldn't the JS/CSS be cached on the client anyway? >>> >> It should, but dont ask me what chrome is doing in the end. > > Are you running the application from the built in http server? Or are you > using fastcgi/nginx ? I am using the integrated http server for development and production. > > I believe the built in http server sends only minimal headers. It doesn't > send Last Modified or any other caching headers. It got me by surprise > also. But it makes sense. During development you're unlikely need any > caching at all and thats what the built in http server was designed for. > But its also good for "embedded" devices :) >> Also I need to support different screen resolutions (qvga and vga) - >> done via html >> body id and css. So I don't see that much sense in caching so dynamic >> pages, but >> may I be wrong :) > > Well I never had to do this but, if the above works for you (the CSS/JS > caching). With the cppcms cache you're caching the content. > > Provided that: > 1) You can cache JS/CSS files in chrome > 2) Most of your JS/CSS is is not inline with HTML > 3) The rest you can cache on the server side > > I think you shouldn't need PJAX at all. Judging by the difference in speed > you get due to not loading JS/CSS on every page load, that is likely your > bottleneck. > Okay.. so my bottleneck is the integrated http server with its minimal http header. I can try to use a normal http server for the cppcms app, but I like the idea to have one executable to provide the whole web app with a http server. Maybe it is enough to enable cppcms caching. I need to rerun some tests/benchmarks. The cppcms app is only used for device configuration, where as the main goal of the device is to provide visualization. So the main resources like RAM/CPU must be available to the visualization. -- Christian Gmeiner, MSc |
From: Artyom B. <art...@ya...> - 2012-06-21 09:36:41
|
----- Original Message ----- > From: Christian Gmeiner <chr...@gm...> > To: cpp...@li... > Cc: > Sent: Wednesday, June 20, 2012 5:34 PM > Subject: [Cppcms-users] Multiple class of render() > > Hi all, > > I found an interesting jquery lib, which speeds up page switching a > lot. This seems to > solve my performance problems I have on my embedded device. > Have a loot at it: https://github.com/defunkt/jquery-pjax > > I have replaced all calls of render with ajax_render, which looks like: > > void Base::ajax_render(std::string template_name, cppcms::base_content > &content) > { > bool chromeless = false; > if (request().getenv("HTTP_X_PJAX") == "true") > { > chromeless = true; > } > > BOOSTER_DEBUG("ajax_render") << "chromeless: " > << chromeless; > > if (chromeless) > { > render(template_name, content); > } > else > { > static content::master m; > render("header", m); > render(template_name, content); > > // as a template for footer is an overkill, we do it here > response().out() << " </div>\n"; > response().out() << "</body>\n"; > response().out() << "</html>\n"; > } > } > > Is the usage of multiple render class the best solution? > It seems to me as classic application of multiple skins. For example create one skin (basic HTML header, footer) for "PAJAX" and other for normal HTML. That what I would do. But this approach is fine as well. Also small note > ___static___ content::master m; It seems to me bad idea... Multiple threads can access same object. So unless you make sure m does not change be careful. Artyom Beilis ------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > thanks > -- > Christian Gmeiner, MSc > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: <ele...@ex...> - 2012-06-21 09:38:58
|
> Okay.. so my bottleneck is the integrated http server with its minimal > http header. > I can try to use a normal http server for the cppcms app, but I like > the idea to have > one executable to provide the whole web app with a http server. Maybe > it is enough > to enable cppcms caching. I need to rerun some tests/benchmarks. If JS/CSS is your bottle neck then cppcms cache isn't going to help you much unless you put all your JS/CSS inline with HTML in which case it's is still going to run slow. My nginx uses about 8MB of resident memory, but is fastest. Lighthttpd uses about 2-3MB :) I think it's a sacrifice well spent. I know the idea of running a single executable may be appealing but in practice using fastcgi + small webserver is a better option. Petr |
From: Artyom B. <art...@ya...> - 2012-06-21 09:46:13
|
Also if you have few js files you need to cache you can create your own function that servers them at application level. Mount with expression like /static/files/(foo|bar).js And then serve them from the application. And setup your own headers for files caching. Take a look on this guide: http://cppcms.com/wikipp/en/page/cppcms_1x_serving_static_files Also it is not so hard to add timestamps and cache headers to the internal file server. So if the patch would be given I'll gladly apply it. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ ----- Original Message ----- > From: "ele...@ex..." <ele...@ex...> > To: cpp...@li... > Cc: > Sent: Thursday, June 21, 2012 12:38 PM > Subject: Re: [Cppcms-users] Multiple class of render() > >> Okay.. so my bottleneck is the integrated http server with its minimal >> http header. >> I can try to use a normal http server for the cppcms app, but I like >> the idea to have >> one executable to provide the whole web app with a http server. Maybe >> it is enough >> to enable cppcms caching. I need to rerun some tests/benchmarks. > > If JS/CSS is your bottle neck then cppcms cache isn't going to help you > much unless you put all your JS/CSS inline with HTML in which case it's is > still going to run slow. > > My nginx uses about 8MB of resident memory, but is fastest. > Lighthttpd uses about 2-3MB :) > > I think it's a sacrifice well spent. > > I know the idea of running a single executable may be appealing but in > practice using fastcgi + small webserver is a better option. > > Petr > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |