一起谈.NET技术,基于.NET的大型Web站点StackOverflow架构分析

原文链接:Stack Overflow Architecture Update - Now At 95 Million Page Views A Month

编译/博客园

Stack Overflow网址:http://stackoverflow.com/

当前访问量:每月9500PV(每天300多万PV)

当前Alexa排名:149

所用.NET技术:C#、Visual Studio 2010 Team Suite、ASP.NET 4、ASP.NET MVC 3、Razor、LINQ to SQL+raw SQL

下面是英文原文:

A lot has happened since my first article on the Stack Overflow Architecture(2009-8-5). Contrary to the theme of that last article, which lavished attention on Stack Overflow's dedication to a scale-up strategy, Stack Overflow has both grown up and out in the last few years.

自从2009年8月发布了第一篇关于“Stack Overflow 架构”方面的文章,Stack Overflow已经发生了很大的变化。那篇文章更多关注的是Stack Overflow如何解决网站的扩展性(scale-up)问题,而经过几年的发展,Stack Overflow已经长大成人,成长为了大型网站。

Stack Overflow has grown up by more then doubling in size to over 16 million users and multiplying its number of page views nearly 6 times to 95 million page views a month.  

现在与2009年相比,Stack Overflow每月独立访问用户翻了一倍,超过1600万;每月PV翻了近6倍,达到9500万。

Stack Overflow has grown out by expanding into the Stack Exchange Network, which includes Stack Overflow, Server Fault, and Super User for a grand total of 43 different sites. That's a lot of fruitful multiplying going on.

Stack Overflow新增了很多站点,比如Server Fault, Super User等,共有43个不同站点组成了Stack Exchange Network,可谓硕果累累,迅猛增长。

What hasn't changed is Stack Overflow's openness about what they are doing. And that's what prompted this update. A recent series of posts talks a lot about how they've been handling their growth: Stack Exchange’s Architecture in Bullet PointsStack Overflow’s New York Data CenterDesigning For Scalability of Management and Fault ToleranceStack Overflow Search — Now 81% LessStack Overflow Network ConfigurationDoes StackOverflow use caching and if so, how?Which tools and technologies build the Stack Exchange Network?.

Stack Overflow的变化翻天覆地,而不变的是他们开放的心态,所以才有了这篇架构分享的文章。最近,他们写了一系列文章分享他们如何应对这样的快速增长。

Some of the more obvious differences across time are:
穿越时空,我们来看看有哪些明显的变化?

  • Just More. More users, more page views, more datacenters, more sites, more developers, more operating systems, more databases, more machines. Just a lot more of more.
    更多:更多的用户,更多的PV,更多的数据中心,更多的站点,更多的开发者,更多的操作系统,更多的数据库,更多的服务器...
  • Linux. Stack Overflow was known for their Windows stack, now they are using a lot more Linux machines for HAProxy, Redis, Bacula, Nagios, logs, and routers. All support functions seem to be handled by Linux, which has required the development of parallel release processes.
    Linux:Stack Overflow因使用Windows系统而著称,现在他们使用越来越多的Linux服务器,比如HAProxy(负载均衡), Redis(NoSQL数据库), Bacula(数据备份系统), Nagios(远程监控软件), 日志, 路由器都运行于Linux系统,几乎所有需要并行处理的功能都是由Linux处理(这句话的翻译可能不准确)。
  • Fault Tolerance. Stack Overflow is now being served by two different switches on two different internet connections, they've added redundant machines, and some functions have moved to a second datacenter.
    容错:Stack Overflow使用了两条不同的互联网线路,增加了更多的冗余服务器,将一些网站服务运行于第二个数据中心。
  • NoSQL. Redis is now used as a caching layer for the entire network. There wasn't a separate caching tier before so this a big change, as is using a NoSQL database on Linux.
    NoSQL:Redis作为整个网站的缓存层。这是一个巨大的改变,以前并没有将缓存作为一个独立的层分离出来。Redis运行于Linux。

Unfortunately, I couldn't find any coverage on some of the open questions I had last time, like how they were going to deal with multi-tenancy across so many diffrent properties, but there's still plenty to learn from. Here's a roll up a few different sources:

遗憾的是,一些我关注的问题并没有从中找到答案,比如面对这么多不同的系统,如何解决多租户的问题(Multi-tenancy 是一种软件体系结构,在这种体系结构中软件运行在 software as a service 服务商的服务器上,服务于多个客户组织即 tenant)。但是,从中我们依然可以学到很多。下面是收集的一些数据列表:

The Stats

  • 95 Million Page Views a Month
  • 800 HTTP requests a second
  • 180 DNS requests a second
  • 55 Megabits per second
  • 16 Million Users  - Traffic to Stack Overflow grew 131% in 2010, to 16.6 million global monthly uniques. 

Data Centers

  • 1 Rack with Peak Internet in OR (Hosts our chat and Data Explorer)
  • 2 Racks with Peer 1 in NY (Hosts the rest of the Stack Exchange Network)

Hardware

  • 10 Dell R610 IIS web servers (3 dedicated to Stack Overflow):

    • 1x Intel Xeon Processor E5640 @ 2.66 GHz Quad Core with 8 threads
    • 16 GB RAM
    • Windows Server 2008 R2
  • 2 Dell R710 database servers:

    • 2x Intel Xeon Processor X5680 @ 3.33 GHz
    • 64 GB RAM
    • 8 spindles
    • SQL Server 2008 R2
  • 2 Dell R610 HAProxy servers:

    • 1x Intel Xeon Processor E5640 @ 2.66 GHz
    • 4 GB RAM
    • Ubuntu Server
  • 2 Dell R610 Redis servers:

    • 2x Intel Xeon Processor E5640 @ 2.66 GHz
    • 16 GB RAM
    • CentOS
  • 1 Dell R610 Linux backup server running Bacula:

    • 1x Intel Xeon Processor E5640 @ 2.66 GHz
    • 32 GB RAM
  • 1 Dell R610 Linux management server for Nagios and logs:

    • 1x Intel Xeon Processor E5640 @ 2.66 GHz
    • 32 GB RAM
  • 2 Dell R610 VMWare ESXi domain controllers:

    • 1x Intel Xeon Processor E5640 @ 2.66 GHz
    • 16 GB RAM
  • 2 Linux routers
  • 5 Dell Power Connect switches

Dev Tools

  • C#: Language
  • Visual Studio 2010 Team Suite: IDE
  • Microsoft ASP.NET (version 4.0): Framework
  • ASP.NET MVC 3: Web Framework
  • Razor: View Engine
  • jQuery 1.4.2: Browser Framework:
  • LINQ to SQL, some raw SQL: Data Access Layer
  • Mercurial and Kiln: Source Control(分布式版本控制系统)
  • Beyond Compare 3: Compare Tool(文件比较工具)

Software and Technologies Used

  • Stack Overflow uses a WISC stack via BizSpark
  • Windows Server 2008 R2 x64: Operating System
  • SQL Server 2008 R2 running Microsoft Windows Server 2008 Enterprise Edition x64: Database
  • Ubuntu Server
  • CentOS
  • IIS 7.0: Web Server
  • HAProxy: for load balancing(高性能的负载TCP/HTTP均衡器)
  • Redis: used as the distributed caching layer.(作为分布式缓存层的NoSQL数据库)
  • CruiseControl.NET: for builds and automated deployment(.NET平台的持续集成工具)
  • Lucene.NET:  for search
  • Bacula: for backups(开源的数据备份系统)
  • Nagios: (with n2rrd and drraw plugins) for monitoring(监视系统运行状态和网络信息的远程监控软件)
  • Splunk: for logs(日志分析工具)
  • SQL Monitor: from Red Gate - for SQL Server monitoring
  • Bind: for DNS
  • Rovio:  a little robot (a real robot) allowing remote developers to visit the office “virtually.”
  • Pingdom:  an external monitor and alert service.(网站监控服务及网站速度测试工具)

External Bits

Code that is not included as part of the development tools:

  • reCAPTCHA(用于验证码验证,已被Google收购)
  • DotNetOpenId(.NET 平台上的 OpenID 实现方案)
  • WMD - Now developed as open source. See github network graph (轻量级所见即所得编辑器)
  • Prettify(代码高亮显示)
  • Google Analytics
  • Cruise Control .NET
  • HAProxy(负载均衡)
  • Cacti(网络流量监测图形分析工具)
  • MarkdownSharp(Markdown文本处理器的C#实现)
  • Flot(基于JQuery的纯JavaScript实现的绘图库)
  • Nginx(反向代理服务器)
  • Kiln(分布式版本控制系统)
  • CDN: none, all static content is served off the sstatic.net, which is a fast, cookieless domain intended for static content delivered to the Stack Exchange family of websites.
    (没有使用CDN,用一个专门的域名sstatic.net传递所有的静态内容)

Developers and System Administrators

  • 14 Developers
  • 2 System Administrators

Content

  • License: Creative Commons Attribution-Share Alike 2.5 Generic
  • Standards: OpenSearch, Atom
  • Host: PEAK Internet

More Architecture and Lessons Learned

  • HAProxy is used instead of Windows NLB because HAProxy is cheap, easy, free, works great as a 512MB VM “device” on a network via Hyper-V. It also works in front of the boxes so it’s completely transparent to them, and easier to troubleshoot as a different networking layer instead of being intermixed with all your windows configuration.
    用HAProxy取代了Windows NLB,HAProxy成本更低,更易于使用,通过Hyper-V可以很好地运行于512M内存的虚拟机。它工作于服务器群的最前端,对所有的服务器都透明。相比于原来混杂在一起的Windows配置,它运行于一个独立的网络层,更易于维护与故障处理。
  • A CDN is not used because even “cheap” CDNs like Amazon one are very expensive relative to the bandwidth they get bundled into their existing host’s plan. The least they could pay is $1k/month based on Amazon’s CDN rates and their bandwidth usage.
    没有使用CDN,即使使用像Amazon那样与主机空间捆绑在一起的看起来“便宜”的CDN,实际的费用也是很高的,至少需要1000美元/月。
  • Backup is to disk for fast retrieval and to tape for historical archiving.
    备份方案有两种,一种用于快速恢复的磁盘备份,一种用于历史数据存档的磁带备份。
  • Full Text Search in SQL Server is very badly integrated, buggy, deeply incompetent, so they went to Lucene.
    SQL Server的全文索引是非常差劲的,所以他们用Lucene.NET。
  • Mostly interested in peak HTTP request figures as this is what they need to make sure they can handle.
    让人很感兴趣的是他们如何处理访问高峰时的HTTP请求。
  • All properties now run on the same Stack Exchange platform. That means Stack Overflow, Super User, Server Fault, Meta, WebApps, and Meta Web Apps are all running on the same software.
    所有这些都运行于Stack Exchange平台,那意味着Stack Overflow, Super User, Server Fault, Meta, WebApps, 和Meta Web Apps都运行于同一个软件。
  • There are separate StackExchange sites because people have different sets of expertise that shouldn't cross over to different topic sites. You can be the greatest chef in the world, but that doesn't qualify you for fixing a server.
    也有一些独立运行的StackExchange站点,服务于那些具有多个专业技能,又不想为了不同的话题在多个站点之间奔波的人。如果你能成为最伟大的主厨,不能因为给你安排了服务员的工作,你就安于现状。
  • They aggressively cache everything.
    他们疯狂地使用缓存。
  • All pages accessed by (and subsequently served to) annonymous users are cached via Output Caching.
    未登录用户访问的所有页面都通过Output Caching进行缓存。
  • Each site has 3 distinct caches: local, site, global.
    每个站点使用三种类型的缓存:本地、站点、全局。
  • local cache: can only be accessed from 1 server/site pair 

    本地缓存:只能被当前站点的当前服务器访问。

    • To limit network latency they use a local "L1" cache, basically HttpRuntime.Cache, of recently set/read values on a server. This would reduce the cache lookup overhead to 0 bytes on the network.
      为了减少网络延时,通常使用HttpRuntime.Cache作为一级缓存,这样可以避免通过网络在缓存服务器上查找的开销。
    • Contains things like user sessions, and pending view count updates.
      缓存内容包含用户会话,视图数的更新。
    • This resides purely in memory, no network or DB access.
      直接缓存在内存中。
  • site cache:  can be accessed by any instance (on any server) of a single site
    站点级缓存:能被同一个站点的所有服务器访问。
    • Most cached values go here, things like hot question id lists and user acceptance rates are good examples
      大部分的缓存都在这一级,比如热点问题ID列表,用户支持率。
    • This resides in Redis (in a distinct DB, purely for easier debugging)
      缓存数据存储在Redis数据库中。
    • Redis is so fast that the slowest part of a cache lookup is the time spent reading and writing bytes to the network.
      Redis速度很快,缓存查找的开销主要在网络传输上。
    • Values are compressed before sending them to Redis. They have plenty of CPU and most of their data are strings so they get a great compression ratio.
      缓存数据发送至Redis之前会被压缩。为什么要压缩呢?因为CPU资源绰绰有余,而且大部分缓存数据是字符串,压缩率会很高,何乐而不为呢。
    • The CPU usage on their Redis machines is 0%.
      Redis服务器上的CPU使用率是0%。
  • global cache: which is shared amongst all sites and servers

    全局缓存:被所有站点和服务器共享。
    • Inboxes, API usage quotas, and a few other truly global things live here
      缓存内容包含收件箱,API使用限额,一些全局设置等。
    • This resides in Redis (in DB 0, likewise for easier debugging)
      缓存于Redis数据库中。
  • Most items in the cache expire after a timeout period (a few minutes usually) and are never explicitly removed. When a specific cache invalidation is required they use Redis messaging to publish removal notices to the "L1" caches.
    大部分缓存项目在超过缓存时间之后会自动过期(通常几分钟),不需要进行删除操作。当需要让一个特定的缓存失效,会通过Redis消息系统给一级缓存发送删除通知。
  • Joel Spolsky is not a Microsoft Loyalist, he doesn't make the technical decisions for Stack Overflow, and considers Microsoft licensing a rounding error. Consider yourself corrected Hacker News commentor.
    Joel Spolsky(Stack Overflow的创始人)并不是微软的忠诚分子,他不负责技术决策,使用微软软件考虑的也只是性价比。Hacker News上一些评论者的说法需要纠正。
  • For their IO system they selected a RAID 10 array of Intel X25 solid state drives . The RAID array eased any concerns about reliability and the SSD drives performed really well in comparision to FusionIO at a much cheaper price.
    对于IO系统,他们选择的是Intel X25 solid state drives(SSD硬盘)的RAID 10磁盘阵列,这样的磁盘阵列,保证了可靠性。这个SSD硬盘用起来感觉不错,而且价格比FusionIO的便宜。
  • The full boat cost for their Microsoft licenses would be approximately $242K. Since Stack Overflow is using Bizspark they are not paying near the full sticker price, but that's the max they could pay.
    使用的这些微软软件,如果全部购买的话,总费用大概在24.2万美元。由于Stack Overflow参加了微软的Bizspark计划,所以不需要付这么多钱,但是要付的话,最多也就是这么多。

Related Articles

时间: 2024-09-01 03:17:40

一起谈.NET技术,基于.NET的大型Web站点StackOverflow架构分析的相关文章

基于.NET的大型Web站点StackOv“.NET研究”erflow架构分析

原文链接:Stack Overflow Architecture Update - Now At 95 Million Page Views A Month 编译/博客园 Stack Overflow网址:http://stackoverflow.com/ 当前访问量:每月9500PV(每天300多万PV) 当前Alexa排名:149 所用.NET技术:C#.Visual Studio 2010 Team Suite.ASP.NET 4.ASP.NET MVC 3.Razor.LINQ to S

一起谈.NET技术,我眼中的Visual Studio 2010架构工具

影响架构质量的是构建体系架构的思想.原则.实践与架构师的经验,绝不是工具.即使是最优秀的架构工具,也不可能像倚天宝剑一般--倚天一出,谁与争锋--似乎谁握住了这把利刃,就能够成为武林盟主.架构工具可以改善架构师的工作,却不能替换架构的过程.软件开发过程中,最重要的依旧是人. 我在尝鲜Visual Studio 2010架构工具[i]时,偶然看到一篇文章,用夸张的语言吹捧VS 2010架构工具,认为它是架构师最怕程序员知道的新工具.这让我有感而发,我想起数十年前甚嚣尘上的一个理论,那就是CASE工

专业技术顾问王庆友--大型APP服务端架构演化及最佳实践

[51CTO.com原创稿件]在WOT2016移动互联网技术峰会上,王庆友前1号店首席架构师兼独立技术顾问为我们讲述APP服务端的变化过程.王庆友老师从四个方面为我们讲述:架构历史和问题.最新服务端2.0架构.APP架构总结及架构本质的理解. 架构历史和问题 最初架构,可以称为0.1版本,架构本身非常简单了.首先有一个无线接口模块,统一对接APP的请求,内部是利用各个业务开发team提供架包完成业务逻辑返回结果.这个架构有两色,一个是集中式架构,另外是架包物理耦合.对于一开始提供一个简单的APP

一起谈.NET技术,构建高性能ASP.NET站点之一 剖析页面的处理过程(前端)

前言:在对ASP.NET网站进行优化的时候,往往不是只是懂得ASP.NET就足够了的. 在优化的过程中,一般先是找出问题可能存在的地方,然后证明找出的问题就是要解决的问题,确认之后,在进行一些措施.系列文章在结构上的安排是这样的:先讲述前端的调优,我会在文章的标题后面标上"前端",如果是后台代码的调优,我会在标题上标上"后端",如果是数据库设计的调优,我会在标题上标上"数据库",希望大家多多提建议. 本篇主要剖析过程,让大家有个全面的了解,下一篇

一起谈.NET技术,从原理来看Silverlight 4的架构

简介 在前文<<初识Silverlight 4及其架构>>谈到要从多个方面来了解:Silverlight的原理,处理周期,部署,安全性,伸缩性,分布式计算能力,容错能力,等等等等.这篇从原理的角度来看Silverlight 4架构相关的一些事情. 浏览器的插件 前文已经介绍过,整个Silverlight平台中包括一个安装器.这个安装器负责将浏览器插件安装上,并在客户浏览器那里搭建起运行Silverlight程序的基础环境.初次浏览Silverlight内容的客户必须先安装一个浏览器

一起谈.NET技术,构建高性能ASP.NET站点之减少不必要的请求

前言:本篇的一些内容比较的有意思,总结了可能平时大家可以注意到的一些优化点,而且非常的实用. 本篇的议题如下: 识别和分析服务端的性能瓶颈(上) 内存(前篇) 缓存(前篇) CPU(后篇) 处理请求线程(后篇) 提高性能的一些简单改进措施(下) 部署优化(前篇) 减少不必要回传(前篇) 减少不必要的请求(后篇) 搜索引擎问题 热链接问题 验证码(CAPTCHA) 网络刮刀 服务端的要处理的请求越多,无疑服务端的压力也就越大,尤其是有些请求需要访问一些比较昂贵的资源,例如数据库,服务端的文件等.但

一起谈.NET技术,HTML5 - 搭建移动Web应用

关于HTML5 HTML5具有语义学.本地存储.设备访问.连接性.多媒体.平面和三维效果.性能和集成和CSS3八大技术特征.让Web应用进入无插件时代,在功能和性能上逼近桌面应用.促使应用Web化,实现跨平台. HTML5规范草案将于2012年发布候选推荐版,2022年发布计划推荐版.规范的实现似乎还在遥远的未来,其实不然!当前很多浏览器已经部分支持HTML5,caniuse.com提供了详尽的浏览器支持情况.HTML5规范本身并不多,很多相关规范都被独立出来,由浏览器各自实现. 移动Web应

一起谈.NET技术,Visual Studio 2010 Web项目的jQuery版本升级方案

我们知道在Visual Studio 2010的非空Web项目(含Webform和MVC)中,都自动包含了jQuery库在项目的Scripts文件夹中. 但细心的人们都看到了正式版中包含的jQuery版本是1.4.1版,而不是jQuery官方最新发布的1.4.2版.处于新版效率的极大提升以及部分bug的修复,推荐大家跟新使用1.4.2版,而放弃1.4.1版.单个项目的调整比较简单就是把旧版本的删除,然后添加上1.4.2版的相应文件即可.但我们很多人可能更希望是以后创建的项目都是1.4.2版而不是

一起谈.NET技术,构建高性能ASP.NET站点之三 细节决定成败

前言:曾经就因为一个小小的疏忽,从而导致了服务器崩溃了,后来才发现:原来就是因为一个循环而导致的,所以,对"注意细节"这一说法是深有感触. 问题的描述 首先,描述一下故事的背景:(希望大家耐心的故事读完) 在网站中,网页中的分页控件每次显示10条数据,每次点击下一页,就再次去取下一个10条数据.至于分页的方法怎样做,方法有很多,相信这点大家都知道. 过程是这样的:在用户请求数据的时候(考虑到了用户的操作和网站的访问量)我会第一次取出500条数据,然后把数据放在缓存中,也就是说,我取出了