how we build caibangzi.com

24
How we built Caibangzi.com Robin Lu (caibangzi.com)

Upload: robin-lu

Post on 18-Jul-2015

515 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: How we build caibangzi.com

How we built Caibangzi.com

Robin Lu (caibangzi.com)

Page 2: How we build caibangzi.com

IntroductionPersonal Investment Management. Tool + Community

Founders: We are engineers!

Technology:

Ruby On Rails

MySQL,Linux,Lighttpd ...

Page 3: How we build caibangzi.com

TopicsProblems we are facing

Architecture evolution of caibangzi

Maintenance

Q&A

Page 4: How we build caibangzi.com

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

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

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

First ChallengeMay, 2007

Extremely time consuming actions blocked the site.

Performance tuning

Optimize Rails cache

Page 8: How we build caibangzi.com

Second Challenge

August, 2007

We were running out of bandwidth

Solution:

Money

upgrade to 5Mbps

Page 9: How we build caibangzi.com

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

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

Something happened in Oct. 2007

Stock Index reached 6000

Daily pv reached 1 million

Bigger challenge came

Page 12: How we build caibangzi.com

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

2 BoxesWeb Server

event mongrel x 30

caibangzi

rails

MySQL 5

memcachedAPP

Tianyuanjia

Page 14: How we build caibangzi.com

Load balancer

Run with 2 mongrels

behindbalancer

Page 15: How we build caibangzi.com

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

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

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

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

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

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

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

Maintenance

Munin

easy to use and extend

Monit

Crontab

Page 23: How we build caibangzi.com

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

Q&A