How we build caibangzi.com
Transcript of How we build caibangzi.com
![Page 1: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/1.jpg)
How we built Caibangzi.com
Robin Lu (caibangzi.com)
![Page 2: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/2.jpg)
IntroductionPersonal Investment Management. Tool + Community
Founders: We are engineers!
Technology:
Ruby On Rails
MySQL,Linux,Lighttpd ...
![Page 3: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/3.jpg)
TopicsProblems we are facing
Architecture evolution of caibangzi
Maintenance
Q&A
![Page 4: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/4.jpg)
Peaks!
High Peak
Heavy Computation
Visiting Peak, Computation Peak and Cache expiration Peak are in the same time. :...(
![Page 5: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/5.jpg)
Evolution - StartLaunched at March, 2007
Hardware: 1 x 1U server
1xAMD Opteron 250, 2G Memory, 250G SATA, RAID 1
Bandwidth
Shared
less than 3Mbps
![Page 6: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/6.jpg)
Evolution - StartApache 2 + mod_proxy_balancer
mongrel x 8
caibangzi
rails 1.1.6
MySQL 5
memcached
All in one box
![Page 7: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/7.jpg)
First ChallengeMay, 2007
Extremely time consuming actions blocked the site.
Performance tuning
Optimize Rails cache
![Page 8: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/8.jpg)
Second Challenge
August, 2007
We were running out of bandwidth
Solution:
Money
upgrade to 5Mbps
![Page 9: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/9.jpg)
Server upgrading
High growth rate after August, 2007
Hardware upgrading in Sept. 2007
still 1 x 1U
2 x AMD 2214 2.2GHz
4G RAM
![Page 10: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/10.jpg)
Until Sept. 2007Apache 2 + mod_proxy_balancer
mongrel x 20
caibangzi
rails 1.1.6
MySQL 5
memcached
Still in one box
![Page 11: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/11.jpg)
Something happened in Oct. 2007
Stock Index reached 6000
Daily pv reached 1 million
Bigger challenge came
![Page 12: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/12.jpg)
Several Changes We Made
Upgrade bandwidth to 10Mbps
Separate APP server and DB server
Load Balancer
Distributed Computation
![Page 13: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/13.jpg)
2 BoxesWeb Server
event mongrel x 30
caibangzi
rails
MySQL 5
memcachedAPP
Tianyuanjia
![Page 14: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/14.jpg)
Load balancer
Run with 2 mongrels
behindbalancer
![Page 15: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/15.jpg)
Lighttpd 1.4
Load balancerSlow actions block the others with balancer:
by request
by traffic
round-robin
Apache
HAproxy
Nginx
Note: Nginx fixed it with ‘fair’ balancer later
![Page 16: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/16.jpg)
Caibangzi Choice of Balancer
Lighttpd 1.5 beta
proxy-core.balancer = "sqf"
http://redmine.lighttpd.net/issues/show/1362
For Rails application, choice of balancer is sometimes more important than choice of web server
![Page 17: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/17.jpg)
More on Web Server
disable keep-alive
serve static files with web server instead of mongrel
tune configurations according to your web server documentations
![Page 18: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/18.jpg)
Distributed solution
BackgrounDRB
based on Distributed Ruby (DRB)
use ruby thread
high overhead during context switching
very slow when concurrent connections higher than 10
![Page 19: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/19.jpg)
Distributed solution
FastBackground
our own distributed computation solution
based on Eventmachine
simple, but fast and works for us
![Page 20: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/20.jpg)
Rails upgrading
Early of 2008, we upgraded to Rails 2.0
expired several plugins
refactory to be more RESTful
cookie session
multi view => wap.caibangzi.com
![Page 21: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/21.jpg)
Open API
API Based on OAuth
integrate caibangzi into your own sites
Other APPs support several F8 clones
xiaonei.com, hainei.com, UCHome
![Page 22: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/22.jpg)
Maintenance
Munin
easy to use and extend
Monit
Crontab
![Page 23: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/23.jpg)
With all that....we handled:
pv/day 1Mrails req/day 1.8M
peak rails req/sec 160total req/day 5Mpeak req/sec 430
It’s the fact. Not the capacity.Our CPU usage never goes higher
than 30%
![Page 24: How we build caibangzi.com](https://reader034.fdocuments.us/reader034/viewer/2022051400/55aa726b1a28ab652e8b4778/html5/thumbnails/24.jpg)
Q&A