an introduction to apache traffic server

50
An introduction to Apache Traffic Server Leif Hedstrom December 2011

Upload: lykiet

Post on 01-Jan-2017

236 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: An introduction to Apache Traffic Server

An introduction to Apache Traffic Server

Leif  Hedstrom  December  2011  

Page 2: An introduction to Apache Traffic Server

Who am I?

•  One of the drivers to open source Traffic Server (at Yahoo)

•  Committer for Apache Traffic Server •  VP of Apache Traffic Server PMC •  ASF member •  Go Daddy’s Principal Architect for Hosting

[email protected] @zwoop +zwoop

Page 3: An introduction to Apache Traffic Server

History of Traffic Server

2010200520001995

ApacheTraffic Server

YahooTraffic Server

InktomiTraffic Server

Page 4: An introduction to Apache Traffic Server

Plenty of FOSS Proxy Servers

Page 5: An introduction to Apache Traffic Server

ATS HAproxy nginx Squid Varnish mod_proxy Worker Threads Y N N N Y Y Multi-Process N Y Y N Y Y Event-driven Y Y Y Y sometimes Y Plugin APIs Y N Y part Y Y Forward Proxy Y N N Y N Y Reverse Proxy Y Y Y Y Y Y Transp. Proxy Y Y N Y N N Load Balancer weak Y Y Y Y Y Persistent Cache Y N Y Y sorta Y ESI Y N N Y kinda N ICP soon N N Y N N Keep-Alive Y N Y Y Y Y SSL Y N Y Y N Y Pipeline Y N Y Y N Y

Features

Page 6: An introduction to Apache Traffic Server

Mandatory useless benchmark …

0"

20,000"

40,000"

60,000"

80,000"

100,000"

120,000"

ATS"2.1.9" Nginx"0.8.53" Varnish"2.1.5"

Throughp

ut)

Req"/"sec"

Page 7: An introduction to Apache Traffic Server

Less useless benchmark …

0.0#

0.5#

1.0#

1.5#

2.0#

2.5#

3.0#

3.5#

4.0#

0#

20,000#

40,000#

60,000#

80,000#

100,000#

120,000#

ATS#2.1.9# Nginx#0.8.53# Varnish#2.1.5#

Time%to%first%respo

nse%

Throughp

ut%

Req#/#sec# Latency#(ms)#

Page 8: An introduction to Apache Traffic Server

Intermediaries - Forward Proxy

Browser

ForwardProxy

Web site A

Web site B

Web site C

GET http://c.com/ HTTP/1.1

GET / HTTP/1.1Host: c.com

The browser (UA) is explicitly configured to use the FP server as a proxy

Page 9: An introduction to Apache Traffic Server

Intermediaries - Reverse Proxy

Browser

ReverseProxy

Web site A

Web site B

Web site C

GET / HTTP/1.1Host: c.com

GET / HTTP/1.1Host: c.com

The reverse proxy has explicit rules for a.com, b.com and c.com. Other requests are

(typically) denied

Page 10: An introduction to Apache Traffic Server

Intermediaries - Intercepting Proxy

BrowserIntercepting

Proxy

Web site A

Web site B

Web site C

GET / HTTP/1.1Host: c.com

Router or

Firewall

GET / HTTP/1.1Host: c.com

There are no explicit configurations in browser of proxy. The transparent proxy intercepts HTTP requests, and

proxies them to the destination.

Page 11: An introduction to Apache Traffic Server

Web Cash?

h4p://www.flickr.com/photos/amagill/3366720659/  

Page 12: An introduction to Apache Traffic Server

No, Web Cache!

h4p://www.flickr.com/photos/dglazkov/287092560/  

Page 13: An introduction to Apache Traffic Server

Common enemies of performance

3-Way handshake

Congestion control

DNS lookups

Page 14: An introduction to Apache Traffic Server

Common enemies of performance

3-Way handshake

Congestion control

DNS lookups

Page 15: An introduction to Apache Traffic Server

TCP 3-way Handshake

SYN

SYN – ACK

ACK

Established

Client

Server

Page 16: An introduction to Apache Traffic Server

Common enemies of performance

3-Way handshake

Congestion control

DNS lookups

Page 17: An introduction to Apache Traffic Server

Congestion control

#8 #3

#21 . . .

ACK 0-2

ACK 3-8

ACK 9-21

ClientServer

#2 #1 #0

. . .

#9

Page 18: An introduction to Apache Traffic Server

Common enemies of performance

3-Way handshake

Congestion control

DNS lookups

Page 19: An introduction to Apache Traffic Server

http://news.example.com/ http://finance.example.com/ http://groups.example.com/

Page 20: An introduction to Apache Traffic Server

http://news.example.com/ http://finance.example.com/ http://groups.example.com/

vs http://www.example.com/news http://www.example.com/finance http://www.example.com/groups

Page 21: An introduction to Apache Traffic Server

The concurrency problem

Page 22: An introduction to Apache Traffic Server

Solution 1: Multithreading

Thread 1

Thread 2

Thread 3

Thread 1

Thread 3

Time

Single CPU

Thread 1 Thread 2

Thread 3

Thread 1

Thread 3

Time

Dual CPU

Page 23: An introduction to Apache Traffic Server

Problems with multi-threading

"When two trains approach each other at a

crossing, both shall come to a full stop

and neither shall start up again until

the other has gone."

From Wikipedia, Illogical statute passed by Kansas legislation.

Page 24: An introduction to Apache Traffic Server

Solution 2: Event Processing

Event

Loop

Scheduled events

Network events

Disk I/O events

Disk handler

HTTP state machine

Accept handler

Queue

Can generate new events

Page 25: An introduction to Apache Traffic Server

Problems with event processors

Page 26: An introduction to Apache Traffic Server

Traffic Server threads model

n threads per coreA

synchro

nous e

vent pro

cessor

Asynchro

nous e

vent pro

cessor

Asynchro

nous e

vent pro

cessor

...

m threads per disk

Dis

k I/O

thre

ad

Dis

k I/O

thre

ad

Dis

k I/O

thre

ad

...

Various "

adm

in"

thre

ads

Accept th

reads (

per

port

)

Loggin

g thre

ads

~10 threads

Shared Resources

RAM cache Disk cacheStats, logs

etc.

Reloadable

Configs

Page 27: An introduction to Apache Traffic Server

http://www.flickr.com/photos/stuartpilbrow/3345896050/

Page 28: An introduction to Apache Traffic Server

plugin.config

records.config

partition.config

hosting.config

cache.config

update.config

ip_allow.config

storage.config

logs_xml.config

parent.config

remap.config

icp.config

Page 29: An introduction to Apache Traffic Server
Page 30: An introduction to Apache Traffic Server

records.config for reverse proxy CONFIG proxy.config.http.server_port INT 80 CONFIG proxy.config.cache.ram_cache.size INT 1G CONFIG proxy.config.cache.ram_cache_cutoff INT 1M CONFIG proxy.config.reverse_proxy.enabled INT 1 CONFIG proxy.config.url_remap.remap_required INT 1 CONFIG proxy.config.url_remap.pristine_host_hdr INT 0 CONFIG proxy.config.http.negative_caching_enabled INT 1 CONFIG proxy.config.http.negative_caching_lifetime INT 120 CONFIG proxy.config.http.cache.ignore_client_cc_max_age INT 1 CONFIG proxy.config.http.normalize_ae_gzip INT 1

Page 31: An introduction to Apache Traffic Server

records.config for reverse proxy CONFIG proxy.config.http.server_port INT 80 CONFIG proxy.config.cache.ram_cache.size INT 1G CONFIG proxy.config.cache.ram_cache_cutoff INT 1M CONFIG proxy.config.reverse_proxy.enabled INT 1 CONFIG proxy.config.url_remap.remap_required INT 1 CONFIG proxy.config.url_remap.pristine_host_hdr INT 0 CONFIG proxy.config.http.negative_caching_enabled INT 1 CONFIG proxy.config.http.negative_caching_lifetime INT 120 CONFIG proxy.config.http.cache.ignore_client_cc_max_age INT 1 CONFIG proxy.config.http.normalize_ae_gzip INT 1

Page 32: An introduction to Apache Traffic Server

records.config for forward proxy CONFIG proxy.config.http.server_port INT 8080 CONFIG proxy.config.cache.ram_cache.size INT 1G CONFIG proxy.config.cache.ram_cache_cutoff INT 1M CONFIG proxy.config.reverse_proxy.enabled INT 0 CONFIG proxy.config.url_remap.remap_required INT 0 CONFIG proxy.config.url_remap.pristine_host_hdr INT 0 CONFIG proxy.config.http.negative_caching_enabled INT 1 CONFIG proxy.config.http.negative_caching_lifetime INT 120 CONFIG proxy.config.http.cache.ignore_client_cc_max_age INT 1 CONFIG proxy.config.http.normalize_ae_gzip INT 1

Page 33: An introduction to Apache Traffic Server

remap.config examples map http://www.example.com/css http://css.example.com map http://www.example.com http://real.example.com reverse_map http://real.example.com http://www.example.com redirect http://example.com http://www.example.com regex_map http://(.*)\.example.com http://o.example.com/$1 map / http://kitchensink.example.com

Page 34: An introduction to Apache Traffic Server

remap.config examples map http://www.example.com/css http://css.example.com map http://www.example.com http://real.example.com reverse_map http://real.example.com http://www.example.com redirect http://example.com http://www.example.com regex_map http://(.*)\.example.com http://o.example.com/$1 map / http://kitchensink.example.com

Page 35: An introduction to Apache Traffic Server

remap.config examples map http://www.example.com/css http://css.example.com map http://www.example.com http://real.example.com reverse_map http://real.example.com http://www.example.com redirect http://example.com http://www.example.com regex_map http://(.*)\.example.com http://o.example.com/$1 map / http://kitchensink.example.com

Page 36: An introduction to Apache Traffic Server

remap.config examples map http://www.example.com/css http://css.example.com map http://www.example.com http://real.example.com reverse_map http://r.example.com http://www.example.com redirect http://example.com http://www.example.com regex_map http://(.*)\.example.com http://o.example.com/$1 map / http://kitchensink.example.com

Page 37: An introduction to Apache Traffic Server

remap.config examples map http://www.example.com/css http://css.example.com map http://www.example.com http://real.example.com reverse_map http://r.example.com http://www.example.com redirect http://example.com http://www.example.com regex_map http://(.*)\.example.com http://o.example.com/$1 map / http://kitchensink.example.com

Page 38: An introduction to Apache Traffic Server

Some interesting features

§ RAM: Optional compression – Various compression levels supported – Very fast (virtually no overhead using the faster algo)

§ RAM: Several cache eviction algorithms – CLFUS algorithm avoids the classic problem on an LRU during “scans”

§ Disk: Supports various block sizes (SSD) § Disk: Can be tuned for various object sizes § Disk: No file system overhead (RAW disks)

Page 39: An introduction to Apache Traffic Server

Future directions

§ Release early, and often § Full IPv6 support § NPN, SNI and other SSL improvements § Improved memory management, support debug features in e.g. jemalloc and tcmalloc § Optimizations for SSD (“stacked” caches) § More focus on plugins, and plugin APIs

– Hopefully a real load balancer plugin!

Page 40: An introduction to Apache Traffic Server

Was this a huge waste of time, or?

h4p://www.flickr.com/photos/simpologist/16734948/  

Page 41: An introduction to Apache Traffic Server

A versatile tool

41 h4p://www.flickr.com/photos/airosan/2232394342/  

Page 42: An introduction to Apache Traffic Server

Yes, it’s fast, ridiculously fast

42

Page 43: An introduction to Apache Traffic Server

A vibrant community!

TheApacheSoftware�Foundationh t t p : / / w w w . a p a c h e . o r g /

43

Page 44: An introduction to Apache Traffic Server

Artur Bergman tells us if we’re not using SSD drives, we’re

wasting our lives.

Page 45: An introduction to Apache Traffic Server

Artur Bergman tells us if we’re not using SSD drives, we’re

wasting our lives.

I’d say, if you are not using a caching proxy, you’re wasting

your SSDs!

Page 46: An introduction to Apache Traffic Server

46

Page 47: An introduction to Apache Traffic Server

Contact me

47

Page 48: An introduction to Apache Traffic Server

records.config for reverse proxy CONFIG proxy.config.http.server_port INT 80 CONFIG proxy.config.cache.ram_cache.size INT 1G CONFIG proxy.config.cache.ram_cache_cutoff INT 1M CONFIG proxy.config.reverse_proxy.enabled INT 1 CONFIG proxy.config.url_remap.remap_required INT 1 CONFIG proxy.config.url_remap.pristine_host_hdr INT 0 CONFIG proxy.config.http.negative_caching_enabled INT 1 CONFIG proxy.config.http.negative_caching_lifetime INT 120 CONFIG proxy.config.http.cache.ignore_client_cc_max_age INT 1 CONFIG proxy.config.http.normalize_ae_gzip INT 1

Page 49: An introduction to Apache Traffic Server

Four Horseman of Bad Performance

– Data copies – Context Switches – Memory allocation – Lock contention

– Avoid these!

http://pl.atyp.us/content/tech/servers.html

Page 50: An introduction to Apache Traffic Server

Disk cache: “Cyclone”