SlideShare a Scribd company logo
1 of 70
Download to read offline
27 mei 2008

       Folke Lemaitre
      Director of Development
       http://nl.netlog.com/folke




  What we learned about
scalability & high availability
Overview



ā€£ What is Netlog?
ā€£ Translations
ā€£ Network topology
ā€£ Scaling Databases
ā€£ Caching
ā€£ Search
ā€£ Q&A
What is Netlog?
Social Network



ā€£ Create your own proļ¬le
ā€£ Discover your friendsŹ¼ activity
ā€£ Communicate
ā€£ Explore new content
ā€£ Applications
Your Proļ¬le
What: itŹ¼s personal



  ā€£ You rule: itŹ¼s yours

              Music                            YOU
                                                               ANOTHER
                             Photos

  Games

                                                     ANOTHER


                 YOU                  Videos
People



                               Blogs
     Photos

                Relations.
Friend Activity



 ā€£ Share & discover friendsŹ¼ activity
                     Pinguke V
                                        Mari . reageert
      Toon Coppens
                     wijzigt haar       op haar foto
                                                                         Jan Maarten
                                                                         Willems tekent
      uploadt een    profielfoto                                         het gastenboek
      nieuwe foto
                                                                         van nico b
                                                                                          Jaak Noukens
                                                                                          en Jo zijn nu
                                                                                          vrienden

                                                          Stijn Symons
                                                          uploadt een
                                                          nieuwe foto

                       Kenny Gryp
                       tekent het
                       gastenboek van
                       Lorenz Bogaert
Communication: Shouts
Communication: Ratings & Comments
Communication: Private messaging
Communication: Chat
Communication: Clans
Explore


                              Blogs
   Proļ¬les
                  Photos




                           Clans          Music
Events
                 Videos




                           Applications
         Pages
Applications



ā€£ OpenSocial
 ā€¢ sandbox: http://nl.netlog.com/go/developer/opensocial/sandbox=1

ā€£ Ofļ¬cially announced tomorrow@ Google I/O
 ā€¢ Stay tuned!

ā€£ Public launch for june
Developer Pages

      http://nl.netlog.com/go/developer
ItŹ¼s going pretty good




 ā€£ More than 35,000,000 unique members
 ā€£ More than 4,000,000,000 pageviews/Month
 ā€£ 19 languages and more coming up
 ā€£ More than 20 countries
 ā€£ Current Alexa Top-100 ranking
                              (most visited web sites in the world)


 ā€£ Current ComScore Europe Top-10 ranking
0
                                                                                                                                                          50.000.000
                                                                                                                                                                          100.000.000
                                                                                                                                                                                          150.000.000
                                                                                                                                                                                                          200.000.000
                                                                                                                                    Ja
                                                                                                                                       nu




                                                          16%



                               3%
                                                                                                                                  Fe       ar
                                                                                                                                      br    y-




                                                       Western Asia
                                                                                                                                       ua 07




                         Eastern Europe
                                                                                                                                     M ry-
                                                                                                                                       ar 07
                                                                                                                                         ch




                                                                                     10%
                                                                                                                                       Ap -07




      22%
                                                                                                                                           ril
                                                                                                                                               -
                                                                                                                                        M 07
                                                                                                                                          ay




 Southern Europe
                                                                                                                                       Ju -07




                                                                                   Americas 3%
                                                                                                                                         ne
                                                                                                                                               -
                                                                                                                                        Ju 07
                                                                                                                                           ly




                                                                                         Northern Europe
                                                                                                                                    Au -0
                                                                                                                                        gu 7
                                                                                                                                          st
                                                                                                                                               -0
                                                                                                                                                  7
                                                                                                                                   O
                                                                                                                                     c
                                                                                                                                 N tob
                                                                                                                                  ov er
                                                                                                                                                                                                                          Monthly Visits




                                                                                                                                    e          -0
                                                                                                                                 D mb 7
                                                                                                                                  ec e
                                                                                                                                    em r-0




                                                      46%
                                                                                                                                   Ja be 7
                                                                                                                                      nu r-0
                                                                                                                                  Fe ary 7




                                                 Western Europe
                                                                                                                                    br -0
                                                                                                                                       ua 8
                                                                                                                                                                                                                                                  ItŹ¼s going pretty good




                                                                                                                                     M ry-
                                                                                                                                       ar 08
                                                                                                                                         ch
                                                                                                                                       Ap -08
                                                                                                                                           ril
                                                                                                                                               -0
                                                                                                                                                  8




                     0
                                    10.000.000
                                                         20.000.000
                                                                      30.000.000
                                                                                          40.000.000




  Ja
     nu
                                                                                                                                                      0
                                                                                                                                                          1.250.000.000
                                                                                                                                                                          2.500.000.000
                                                                                                                                                                                          3.750.000.000
                                                                                                                                                                                                          5.000.000.000




 Fe ary                                                                                                                             Ja
    br -0                                                                                                                             n
       ua 7                                                                                                                       Fe uar
    M ry-                                                                                                                           br y-0
       ar 07                                                                                                                            ua 7
         ch                                                                                                                          M ry-
       Ap -07                                                                                                                           ar 0
                                                                                                                                          ch 7
          ril
              -                                                                                                                         Ap -07
       M 07                                                                                                                                ril
         ay
                                                                                                                                        M -07
      Ju -07                                                                                                                              ay
         ne                                                                                                                            Ju -07
              -                                                                                                                           ne
       Ju 07
          l                                                                                                                             Ju -07
   Au y-0
       gu 7                                                                                                                         Au ly-0
          st                                                                                                                            gu 7
              -0                                                                                                                           st
                 7                                                                                                                             -0
  O                                                                                                                                               7
    ct                                                                                                                             O
N obe                                                                                                                                ct
 ov                                                                                                                              N ob
    e r-0                                                                                                                         ov er
                                                                                                                                               -
D mb 7                                                                                                                              e
 ec e                                                                                                                            D mb 07
    em r-0                                                                                                                        ec e
                                                                                                       Monthly Unique Visitors




                                                                                                                                    em r-0
                                                                                                                                                                                                                          Monthly Page Requests




  Ja be 7                                                                                                                          Ja be 7
     nu r-0                                                                                                                           n r-
 Fe ary 7                                                                                                                         Fe uar 07
    br -0                                                                                                                           br y-0
       ua 8                                                                                                                             ua 8
    M ry-                                                                                                                            M ry-
       ar 08                                                                                                                            ar 0
         ch                                                                                                                               ch 8
       Ap -08                                                                                                                           Ap -08
          ril                                                                                                                              ril
              -0                                                                                                                               -0
                 8                                                                                                                                8
ItŹ¼s going pretty good
Translations
19 languages and alot more coming!

                           Slovenčina
         EspaƱol CatalƠ
                                         Svenska
                           suomi     česky
slovenŔčina    Deutsch                      Magyar
                          Nederlands
                franƧais
 Š ŃƒŃŃŠŗŠøŠ¹                   Italiano Afrikaans
          English
         Dansk      TĆ¼rkƧe
Polski                                     Hrvatski
               Lietuvių kalba
   Eesti                         LatvieŔu valoda
          PortuguĆŖs
RomĆ¢nă                                  Š±ŃŠŠ»Š³Š°Ń€ŃŠŗŠø
                Norsk (bokmƄl)
Translate Tool
Template
Parsed Template
Translated Template
Generated PhP code
Template Code
Template Output
Network Topology
Overview


            Netlog Datacenters
                                                               Database Pools

                                                              Slave                  Slave
                                                     Master                 Master
                                                              Slave                  Slave
                                                        User Pool             Activity Pool

                                 Web Cluster
                                                              Slave                  Slave
                                                     Master                 Master
                                                              Slave                  Slave
                                                     Friendships Pool                ...
Internet                   Web Load Balancer
            Firewall
                                                              Memcache Pools


                          Static Load Balancer
                                                               Session Cache

                                                                      Slave
                                                                Master
                                                      General Cache   Slave
                                                                      Html Cache
                                                                      Primary Pool
      CDN
                                   Storage Servers
Web Servers

ā€£ Software
 ā€¢ Apache 2
 ā€¢ Php 5.2.6
 ā€¢ eAccelerator 0.9.5.2 for bytecode caching
 ā€¢ Keepalived for high availability

ā€£ 200 servers
ā€£ 450 000 requests per second
Database Servers



ā€£ MySQL Enterprise 4.1.22
ā€£ 200 database servers
ā€£ 40 thousand tables
ā€£ 70 billion records
ā€£ 60 thousand queries per second
Memcache Servers



ā€£ Memcached 1.2.4
ā€£ 60 servers
ā€£ 250 thousand requests/second
ā€£ 450 GB of memory
Static servers



ā€£ Software:
 ā€¢ Lighttpd
 ā€¢ NginX

ā€£ Used for:
 ā€¢ static ļ¬les: css/javascript/images/...
 ā€¢ user content: photos, videos

ā€£ Content Delivery Network: Akamai & Panther
Other servers



ā€£ OpenSocial:
 ā€¢ Shindig
 ā€¢ Tomcat

ā€£ Search:
 ā€¢ Sphinx
Scaling Databases
Database & Scalability



ā€£ Database pools

ā€£ Replication

ā€£ Partitioning
Database Pools



ā€£ Different data on different database pools:
 ā€¢ messaging
 ā€¢ friendships
 ā€¢ blogs
 ā€¢ music
 ā€¢ videos
 ā€¢ ...
Replication



ā€£ write to one master
ā€£ read from multiple slaves (and master)
ā€£ pros
 ā€¢ easy to implement
 ā€¢ read intensive applications scale very well
ā€£ cons
 ā€¢ write intensive applications donŹ¼t scale
Partitioning (sharding)



ā€£ Divide data on primary key:
 ā€¢ all user data for users with id 1 - 10 in database1
 ā€¢ all user data for users with id 11 - 20 in database2
 ā€¢ ...

ā€£ Best scaling possible
ā€£ How?
 ā€¢ managed in code
 ā€¢ MySQL partitioning (available from version 5.1)
Analyse, analyse, analyse!


ā€£ Tag your queries
 ā€¢   SELECT * FROM USER WHERE userid = 123 /*User::getUser():11 */


ā€£ Analyse mysql slow logs
ā€£ Analyse process lists
ā€£ Analyse based on tags
 ā€¢   1023 User:getUser():230
 ā€¢   512 User::isOnline():124
 ā€¢   10   Activities:getActivity():320


ā€£ minutely cron that checks for ā€œtoo many
 connectionsā€
 ā€¢ if ā€œtoo many connectionsā€, log process list
Caching
Introduction to memcached



ā€£ Developed by Danga Interactive:
  ā€¢ http://www.danga.com/


ā€£ Initially developed for LiveJournal:
  ā€¢ http://www.livejournal.com/


ā€£ OpenSource
Introduction to memcached



ā€£ Least Recently Used
ā€£ Fast!
ā€£ Distributed
ā€£ Automatic failover
ā€£ Big Hash table: set/add/get/delete
What to cache?



ā€£ sessions
ā€£ query caching
ā€£ processed data
ā€£ generated html
Session Cache



ā€£ 99% hit ratio
ā€£ Time to live is 20 minutes
ā€£ Faster than session database
Query Cache



ā€£ Why memcache and not MySQL query cache?
 ā€¢ MySQL invalidates cached queries on a table on
     every update
 ā€¢   different query cache for different replicated
     databases

ā€£ Add to generic database classes
 ā€¢ Cache key is query
Processed data



ā€£ Better to cache processed data than query
 results
HTML Caching
HTML Caching



ā€£ Proļ¬le blocks are fully cached
ā€£ Data needed to generate html is also cached
ā€£ When data changes, html is invalidated, cached
 data updated

ā€£ High cache hit rate on proļ¬le pages
3 ways of caching



ā€£ Cache with TTL

ā€£ Cache forever with invalidate

ā€£ Cache forever with update
Cache with TTL



ā€£ The good:
 ā€¢ Quickly achieve better performance on existing code

ā€£ The bad:
 ā€¢ Users see outdated information
 ā€¢ TTL can not be high
 ā€¢ Caching efļ¬ciency is minimal
Cache with TTL


ā€£ Cache friends for 5 minutes
Cache forever with invalidate



ā€£ The Good:
 ā€¢ fairly easy to implement
 ā€¢ user never sees outdated data
Cache friends forever


ā€£ For memcached this means ttl=0
Invalidate Cache
Cache forever with update



ā€£ The Good:
 ā€¢ Best caching possible
 ā€¢ Can reduce your select queries to the minimum
Update Cache (array)


ā€£ Only update cache when no db queries needed
Update Cache (simple value)



ā€£ No need to check cache
Global Locking



ā€£ Use memcache as locking mechanism
Global Locking: Chat Example

ā€£ Example: add new message to cached shared
 chat thread
Flooding detection



ā€£ User can only redo action A after a timeout
 ā€¢ a guestbook message can only be posted once every
   2 minutes



ā€£ User can not do action A more than X times in T
 minutes
 ā€¢ only 12 failed login attempts per hour are allowed
Flooding detection
Flooding detection



ā€£ User can only redo action A after a timeout
 ā€¢ a guestbook message can only be posted once every
   2 minutes



ā€£ User can not do action A more than X times in T
 minutes
 ā€¢ only 12 failed login attempts per hour are allowed
Search
MySQL full-text search



ā€£ Initially used for our search
  ā€¢ can be very slow
  ā€¢ extra load on most of our databases, since most
   content is searchable

ā€£ Better search engine needed
  ā€¢ Sphinx!
  ā€¢ OpenSource search engine developed by Andrew
   Aksyonoff (http://sphinxsearch.com/)
Sphinx Features



ā€£ very fast indexing
ā€£ very fast searching
 ā€¢ 0.04 seconds average
 ā€¢ 5 million searches / day
 ā€¢ 60 searches / second
ā€£ distributed
ā€£ document ļ¬elds
ā€£ stopwords
ā€£ api available in many languages
 ā€¢   PhP, Java, Python, Ruby, Perl, C++, ...
Sphinx Indexer



ā€£ Index is read-only (except for attributes)
ā€£ Build new index while searching old one
ā€£ How we index:
  ā€¢ rebuild full index from data once in a while (daily,
      weekly)
  ā€¢   generate delta indexes often (every minute, 5
      minutes)
      ā€¢   contains changes for search index since last full index merge
  ā€¢ full index merge of previous index and delta (every
      hour)
Sphinx Search



ā€£ Search query returns list of ids
ā€£ For every result page shown, we fetch data
 associated with ids
 ā€¢ data is cached with memcache for every id
Thank you!




             Questions?

More Related Content

Similar to Netlog: What we learned about scalability & high availability

Gcit1015 power point final
Gcit1015 power point finalGcit1015 power point final
Gcit1015 power point finalmRaKes
Ā 
Gcit1015 power point final
Gcit1015 power point finalGcit1015 power point final
Gcit1015 power point final12208388
Ā 
Strategic Communications Planning
Strategic Communications PlanningStrategic Communications Planning
Strategic Communications PlanningShonali Burke
Ā 
Integrated Marketing - Overman
Integrated Marketing - OvermanIntegrated Marketing - Overman
Integrated Marketing - OvermanEric Overman
Ā 
Eduserv OpenID Meeting: OpenID Today
Eduserv OpenID Meeting: OpenID TodayEduserv OpenID Meeting: OpenID Today
Eduserv OpenID Meeting: OpenID TodayDavid Recordon
Ā 
From content to community
From content to communityFrom content to community
From content to communitypwcom.co.uk Ltd
Ā 

Similar to Netlog: What we learned about scalability & high availability (6)

Gcit1015 power point final
Gcit1015 power point finalGcit1015 power point final
Gcit1015 power point final
Ā 
Gcit1015 power point final
Gcit1015 power point finalGcit1015 power point final
Gcit1015 power point final
Ā 
Strategic Communications Planning
Strategic Communications PlanningStrategic Communications Planning
Strategic Communications Planning
Ā 
Integrated Marketing - Overman
Integrated Marketing - OvermanIntegrated Marketing - Overman
Integrated Marketing - Overman
Ā 
Eduserv OpenID Meeting: OpenID Today
Eduserv OpenID Meeting: OpenID TodayEduserv OpenID Meeting: OpenID Today
Eduserv OpenID Meeting: OpenID Today
Ā 
From content to community
From content to communityFrom content to community
From content to community
Ā 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
Ā 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
Ā 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
Ā 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
Ā 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
Ā 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
Ā 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
Ā 
Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!Commit University
Ā 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
Ā 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
Ā 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
Ā 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
Ā 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
Ā 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Ā 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
Ā 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
Ā 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
Ā 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
Ā 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Ā 
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Ā 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
Ā 
Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Ā 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
Ā 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
Ā 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
Ā 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
Ā 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
Ā 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Ā 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Ā 

Netlog: What we learned about scalability & high availability

  • 1. 27 mei 2008 Folke Lemaitre Director of Development http://nl.netlog.com/folke What we learned about scalability & high availability
  • 2. Overview ā€£ What is Netlog? ā€£ Translations ā€£ Network topology ā€£ Scaling Databases ā€£ Caching ā€£ Search ā€£ Q&A
  • 4. Social Network ā€£ Create your own proļ¬le ā€£ Discover your friendsŹ¼ activity ā€£ Communicate ā€£ Explore new content ā€£ Applications
  • 6. What: itŹ¼s personal ā€£ You rule: itŹ¼s yours Music YOU ANOTHER Photos Games ANOTHER YOU Videos People Blogs Photos Relations.
  • 7. Friend Activity ā€£ Share & discover friendsŹ¼ activity Pinguke V Mari . reageert Toon Coppens wijzigt haar op haar foto Jan Maarten Willems tekent uploadt een profielfoto het gastenboek nieuwe foto van nico b Jaak Noukens en Jo zijn nu vrienden Stijn Symons uploadt een nieuwe foto Kenny Gryp tekent het gastenboek van Lorenz Bogaert
  • 13. Explore Blogs Proļ¬les Photos Clans Music Events Videos Applications Pages
  • 14. Applications ā€£ OpenSocial ā€¢ sandbox: http://nl.netlog.com/go/developer/opensocial/sandbox=1 ā€£ Ofļ¬cially announced tomorrow@ Google I/O ā€¢ Stay tuned! ā€£ Public launch for june
  • 15. Developer Pages http://nl.netlog.com/go/developer
  • 16. ItŹ¼s going pretty good ā€£ More than 35,000,000 unique members ā€£ More than 4,000,000,000 pageviews/Month ā€£ 19 languages and more coming up ā€£ More than 20 countries ā€£ Current Alexa Top-100 ranking (most visited web sites in the world) ā€£ Current ComScore Europe Top-10 ranking
  • 17. 0 50.000.000 100.000.000 150.000.000 200.000.000 Ja nu 16% 3% Fe ar br y- Western Asia ua 07 Eastern Europe M ry- ar 07 ch 10% Ap -07 22% ril - M 07 ay Southern Europe Ju -07 Americas 3% ne - Ju 07 ly Northern Europe Au -0 gu 7 st -0 7 O c N tob ov er Monthly Visits e -0 D mb 7 ec e em r-0 46% Ja be 7 nu r-0 Fe ary 7 Western Europe br -0 ua 8 ItŹ¼s going pretty good M ry- ar 08 ch Ap -08 ril -0 8 0 10.000.000 20.000.000 30.000.000 40.000.000 Ja nu 0 1.250.000.000 2.500.000.000 3.750.000.000 5.000.000.000 Fe ary Ja br -0 n ua 7 Fe uar M ry- br y-0 ar 07 ua 7 ch M ry- Ap -07 ar 0 ch 7 ril - Ap -07 M 07 ril ay M -07 Ju -07 ay ne Ju -07 - ne Ju 07 l Ju -07 Au y-0 gu 7 Au ly-0 st gu 7 -0 st 7 -0 O 7 ct O N obe ct ov N ob e r-0 ov er - D mb 7 e ec e D mb 07 em r-0 ec e Monthly Unique Visitors em r-0 Monthly Page Requests Ja be 7 Ja be 7 nu r-0 n r- Fe ary 7 Fe uar 07 br -0 br y-0 ua 8 ua 8 M ry- M ry- ar 08 ar 0 ch ch 8 Ap -08 Ap -08 ril ril -0 -0 8 8
  • 20. 19 languages and alot more coming! Slovenčina EspaƱol CatalĆ  Svenska suomi česky slovenŔčina Deutsch Magyar Nederlands franƧais Š ŃƒŃŃŠŗŠøŠ¹ Italiano Afrikaans English Dansk TĆ¼rkƧe Polski Hrvatski Lietuvių kalba Eesti LatvieÅ”u valoda PortuguĆŖs RomĆ¢nă Š±ŃŠŠ»Š³Š°Ń€ŃŠŗŠø Norsk (bokmĆ„l)
  • 29. Overview Netlog Datacenters Database Pools Slave Slave Master Master Slave Slave User Pool Activity Pool Web Cluster Slave Slave Master Master Slave Slave Friendships Pool ... Internet Web Load Balancer Firewall Memcache Pools Static Load Balancer Session Cache Slave Master General Cache Slave Html Cache Primary Pool CDN Storage Servers
  • 30. Web Servers ā€£ Software ā€¢ Apache 2 ā€¢ Php 5.2.6 ā€¢ eAccelerator 0.9.5.2 for bytecode caching ā€¢ Keepalived for high availability ā€£ 200 servers ā€£ 450 000 requests per second
  • 31. Database Servers ā€£ MySQL Enterprise 4.1.22 ā€£ 200 database servers ā€£ 40 thousand tables ā€£ 70 billion records ā€£ 60 thousand queries per second
  • 32. Memcache Servers ā€£ Memcached 1.2.4 ā€£ 60 servers ā€£ 250 thousand requests/second ā€£ 450 GB of memory
  • 33. Static servers ā€£ Software: ā€¢ Lighttpd ā€¢ NginX ā€£ Used for: ā€¢ static ļ¬les: css/javascript/images/... ā€¢ user content: photos, videos ā€£ Content Delivery Network: Akamai & Panther
  • 34. Other servers ā€£ OpenSocial: ā€¢ Shindig ā€¢ Tomcat ā€£ Search: ā€¢ Sphinx
  • 36. Database & Scalability ā€£ Database pools ā€£ Replication ā€£ Partitioning
  • 37. Database Pools ā€£ Different data on different database pools: ā€¢ messaging ā€¢ friendships ā€¢ blogs ā€¢ music ā€¢ videos ā€¢ ...
  • 38. Replication ā€£ write to one master ā€£ read from multiple slaves (and master) ā€£ pros ā€¢ easy to implement ā€¢ read intensive applications scale very well ā€£ cons ā€¢ write intensive applications donŹ¼t scale
  • 39. Partitioning (sharding) ā€£ Divide data on primary key: ā€¢ all user data for users with id 1 - 10 in database1 ā€¢ all user data for users with id 11 - 20 in database2 ā€¢ ... ā€£ Best scaling possible ā€£ How? ā€¢ managed in code ā€¢ MySQL partitioning (available from version 5.1)
  • 40. Analyse, analyse, analyse! ā€£ Tag your queries ā€¢ SELECT * FROM USER WHERE userid = 123 /*User::getUser():11 */ ā€£ Analyse mysql slow logs ā€£ Analyse process lists ā€£ Analyse based on tags ā€¢ 1023 User:getUser():230 ā€¢ 512 User::isOnline():124 ā€¢ 10 Activities:getActivity():320 ā€£ minutely cron that checks for ā€œtoo many connectionsā€ ā€¢ if ā€œtoo many connectionsā€, log process list
  • 42. Introduction to memcached ā€£ Developed by Danga Interactive: ā€¢ http://www.danga.com/ ā€£ Initially developed for LiveJournal: ā€¢ http://www.livejournal.com/ ā€£ OpenSource
  • 43. Introduction to memcached ā€£ Least Recently Used ā€£ Fast! ā€£ Distributed ā€£ Automatic failover ā€£ Big Hash table: set/add/get/delete
  • 44. What to cache? ā€£ sessions ā€£ query caching ā€£ processed data ā€£ generated html
  • 45. Session Cache ā€£ 99% hit ratio ā€£ Time to live is 20 minutes ā€£ Faster than session database
  • 46. Query Cache ā€£ Why memcache and not MySQL query cache? ā€¢ MySQL invalidates cached queries on a table on every update ā€¢ different query cache for different replicated databases ā€£ Add to generic database classes ā€¢ Cache key is query
  • 47. Processed data ā€£ Better to cache processed data than query results
  • 49. HTML Caching ā€£ Proļ¬le blocks are fully cached ā€£ Data needed to generate html is also cached ā€£ When data changes, html is invalidated, cached data updated ā€£ High cache hit rate on proļ¬le pages
  • 50. 3 ways of caching ā€£ Cache with TTL ā€£ Cache forever with invalidate ā€£ Cache forever with update
  • 51. Cache with TTL ā€£ The good: ā€¢ Quickly achieve better performance on existing code ā€£ The bad: ā€¢ Users see outdated information ā€¢ TTL can not be high ā€¢ Caching efļ¬ciency is minimal
  • 52. Cache with TTL ā€£ Cache friends for 5 minutes
  • 53. Cache forever with invalidate ā€£ The Good: ā€¢ fairly easy to implement ā€¢ user never sees outdated data
  • 54. Cache friends forever ā€£ For memcached this means ttl=0
  • 56. Cache forever with update ā€£ The Good: ā€¢ Best caching possible ā€¢ Can reduce your select queries to the minimum
  • 57. Update Cache (array) ā€£ Only update cache when no db queries needed
  • 58. Update Cache (simple value) ā€£ No need to check cache
  • 59. Global Locking ā€£ Use memcache as locking mechanism
  • 60. Global Locking: Chat Example ā€£ Example: add new message to cached shared chat thread
  • 61. Flooding detection ā€£ User can only redo action A after a timeout ā€¢ a guestbook message can only be posted once every 2 minutes ā€£ User can not do action A more than X times in T minutes ā€¢ only 12 failed login attempts per hour are allowed
  • 63. Flooding detection ā€£ User can only redo action A after a timeout ā€¢ a guestbook message can only be posted once every 2 minutes ā€£ User can not do action A more than X times in T minutes ā€¢ only 12 failed login attempts per hour are allowed
  • 65. MySQL full-text search ā€£ Initially used for our search ā€¢ can be very slow ā€¢ extra load on most of our databases, since most content is searchable ā€£ Better search engine needed ā€¢ Sphinx! ā€¢ OpenSource search engine developed by Andrew Aksyonoff (http://sphinxsearch.com/)
  • 66. Sphinx Features ā€£ very fast indexing ā€£ very fast searching ā€¢ 0.04 seconds average ā€¢ 5 million searches / day ā€¢ 60 searches / second ā€£ distributed ā€£ document ļ¬elds ā€£ stopwords ā€£ api available in many languages ā€¢ PhP, Java, Python, Ruby, Perl, C++, ...
  • 67. Sphinx Indexer ā€£ Index is read-only (except for attributes) ā€£ Build new index while searching old one ā€£ How we index: ā€¢ rebuild full index from data once in a while (daily, weekly) ā€¢ generate delta indexes often (every minute, 5 minutes) ā€¢ contains changes for search index since last full index merge ā€¢ full index merge of previous index and delta (every hour)
  • 68. Sphinx Search ā€£ Search query returns list of ids ā€£ For every result page shown, we fetch data associated with ids ā€¢ data is cached with memcache for every id
  • 69.
  • 70. Thank you! Questions?