Practise C++ in web <ul><li>挑战 web 极限 </li></ul><ul><li>邵军辉 </li></ul><ul><li>人人网 </li></ul>
Argument <ul><li>Scripting is most widely used in server-side </li></ul><ul><li>C++ is faster than Java in most cases  #1 ...
 
Effective <ul><li>Java 40 servers </li></ul><ul><li>C++  6 servers </li></ul>
cgi-bin
Architecture
Under Hood <ul><li>fastcgi since mid-1990s </li></ul><ul><li>ctemplate simple but powerful XSS safe </li></ul>
Template <ul><li>Hello {{ NAME }}, Velocity China ${{ YEAR }}! </li></ul><ul><li>{{ # ONE_RESULT }} <a href=&quot;{{ JUMP_...
1 st  version <ul><li>asynchronous sub task </li></ul><ul><li>build sub dictionary </li></ul><ul><li>expand template with ...
2 nd  version <ul><li>fetch remote data </li></ul><ul><li>build dictionary </li></ul><ul><li>expand template with dictiona...
Sample <ul><li>struct  Action { </li></ul><ul><li>virtual bool  Match( const  std::string&  url )  const  = 0; </li></ul><...
Sample <ul><li>struct  TemplateAction : public Action { </li></ul><ul><li>bool  Match( const  std::string&  url )  const  ...
Deployment & Operation <ul><li>embeded spawn-fastcgi mechanism /path/to/cwfd --thread 4 --port 3000 </li></ul><ul><li>temp...
Quality Control <ul><li>unit test </li></ul>
Quality Control <ul><li>unit test </li></ul><ul><li>breakpad </li></ul>
Improvement <ul><li>降低开发维护门槛 </li></ul><ul><li>成本 </li></ul><ul><li>unit test </li></ul>
Resource <ul><li>http://www.cherrystonesoftware.com/doc/Algorithmic Performance .pdf </li></ul><ul><li>http://en.wikipedia...
Q & A
Upcoming SlideShare
Loading in...5
×

Practise c++ in web

819

Published on

use c

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
819
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • load 降低 50% user cpu 降低
  • Practise c++ in web

    1. 1. Practise C++ in web <ul><li>挑战 web 极限 </li></ul><ul><li>邵军辉 </li></ul><ul><li>人人网 </li></ul>
    2. 2. Argument <ul><li>Scripting is most widely used in server-side </li></ul><ul><li>C++ is faster than Java in most cases #1 </li></ul><ul><li>C++ is the hardest programming language </li></ul>
    3. 4. Effective <ul><li>Java 40 servers </li></ul><ul><li>C++ 6 servers </li></ul>
    4. 5. cgi-bin
    5. 6. Architecture
    6. 7. Under Hood <ul><li>fastcgi since mid-1990s </li></ul><ul><li>ctemplate simple but powerful XSS safe </li></ul>
    7. 8. Template <ul><li>Hello {{ NAME }}, Velocity China ${{ YEAR }}! </li></ul><ul><li>{{ # ONE_RESULT }} <a href=&quot;{{ JUMP_TO_URL : h }}&quot;>{{ LEAD_LINE }}</a> … … {{/ ONE_RESULT }} </li></ul><ul><li>{{ > PAGE_FOOTING }} </li></ul>
    8. 9. 1 st version <ul><li>asynchronous sub task </li></ul><ul><li>build sub dictionary </li></ul><ul><li>expand template with dictionaries </li></ul>
    9. 10. 2 nd version <ul><li>fetch remote data </li></ul><ul><li>build dictionary </li></ul><ul><li>expand template with dictionary </li></ul>
    10. 11. Sample <ul><li>struct Action { </li></ul><ul><li>virtual bool Match( const std::string& url ) const = 0; </li></ul><ul><li>virtual HttpStatusCode Process(Request*, Response*) = 0; </li></ul><ul><li>}; </li></ul>
    11. 12. Sample <ul><li>struct TemplateAction : public Action { </li></ul><ul><li>bool Match( const std::string& url ) const { </li></ul><ul><li> return boost :: starts_with( url , &quot; /feedretrieve.do &quot;); } </li></ul><ul><li>HttpStatusCode Process(Request*, Response* res ) { res ->header().set_status_code(HC_OK, &quot; OK &quot;); </li></ul><ul><li> res ->header().Add(HH_CONTENT_TYPE, &quot; text/html; charset=utf-8 &quot;); </li></ul><ul><li> res ->OutputHeader(); </li></ul><ul><li> res- >WriteRaw(&quot; <h1>foo</h1> &quot;); </li></ul><ul><li> return HC_OK ; </li></ul><ul><li>} </li></ul><ul><li>}; </li></ul>
    12. 13. Deployment & Operation <ul><li>embeded spawn-fastcgi mechanism /path/to/cwfd --thread 4 --port 3000 </li></ul><ul><li>template update pkill -60 cwfd </li></ul><ul><li>program update on the fly </li></ul><ul><li>network problem ack packet lost more servers than need </li></ul>
    13. 14. Quality Control <ul><li>unit test </li></ul>
    14. 15. Quality Control <ul><li>unit test </li></ul><ul><li>breakpad </li></ul>
    15. 16. Improvement <ul><li>降低开发维护门槛 </li></ul><ul><li>成本 </li></ul><ul><li>unit test </li></ul>
    16. 17. Resource <ul><li>http://www.cherrystonesoftware.com/doc/Algorithmic Performance .pdf </li></ul><ul><li>http://en.wikipedia.org/wiki/ Comparison_of_Java_and_C++ </li></ul><ul><li>http://news. netcraft .com/archives/2010/01/ </li></ul><ul><li>http://www. fastcgi .com/drupal/node/5 </li></ul><ul><li>http://code.google.com/p/ google-ctemplate / </li></ul><ul><li>http://code.google.com/p/ google-breakpad / </li></ul><ul><li>http://code.google.com/p/ googletest / </li></ul><ul><li>http://code.google.com/p/ google-perftools / </li></ul><ul><li>http:// nginx .org/ </li></ul><ul><li>http://www. fastcgi .com/ </li></ul><ul><li>http://redmine.lighttpd.net/projects/ spawn-fcgi </li></ul><ul><li>http://blog.sina.com.cn/xiaowenzi22 </li></ul>
    17. 18. Q & A
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×