Ускоряем загрузку картинок вебсокетами

32
Faster images through the WebSockets? Yarik Ponomarenko

Upload: 2-

Post on 26-Jun-2015

331 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Ускоряем загрузку картинок вебсокетами

Faster images through the WebSockets?Yarik Ponomarenko

Page 2: Ускоряем загрузку картинок вебсокетами

problem

Too many images at the webpage are downloaded slowly

Page 3: Ускоряем загрузку картинок вебсокетами

How does browser load a image?

● find <img>

● connect to server

● send the request

● wait for response

● receive the response

● draw received image

Browser Server

Page 4: Ускоряем загрузку картинок вебсокетами

Next is always waiting until previous is finished

Image 1

Server

Image 2

Page 5: Ускоряем загрузку картинок вебсокетами

Browser use several connectionsQueue 1

Queue 2

Queue ...

Queue 6

Page 6: Ускоряем загрузку картинок вебсокетами

"keep alive" connectionswithout

keep alive

Page 7: Ускоряем загрузку картинок вебсокетами

Current tricks to load images faster

● CDN

● combine several images into the sprites

● some few different (fake) domains

Page 8: Ускоряем загрузку картинок вебсокетами

What bad in HTTP Get?

● one shot - one hit

● one image - one request

● requests are performed in sync queues

Page 9: Ускоряем загрузку картинок вебсокетами

the silver bullet trick is:

using websocket connection to retrieve images

in async way

Page 10: Ускоряем загрузку картинок вебсокетами

WebSocket (WS://)

● persistent

● duplex

● async

Page 11: Ускоряем загрузку картинок вебсокетами

why that faster?HTTP GET

WebSocket

Page 12: Ускоряем загрузку картинок вебсокетами

plan

1. establish WS connection

2. find all image's "src" at page

3. send the pack of requests to server

4. retrieve the images

5. draw them

6. ???

7. profit

Page 13: Ускоряем загрузку картинок вебсокетами

client

Page 14: Ускоряем загрузку картинок вебсокетами

backend

Page 15: Ускоряем загрузку картинок вебсокетами

base64 has 30% lower density

Page 16: Ускоряем загрузку картинок вебсокетами

how to read the binary WS frame?

Page 17: Ускоряем загрузку картинок вебсокетами

another way to read blob

Page 18: Ускоряем загрузку картинок вебсокетами

many requests in one connection:send the message id

Page 19: Ускоряем загрузку картинок вебсокетами

many requests in one connection:return the message id

Page 20: Ускоряем загрузку картинок вебсокетами

many requests in one connection:parse the message id in response

Page 21: Ускоряем загрузку картинок вебсокетами

Disadvantages

● browser doesn't cache websockets

● we still need several connections to increase

the network utilization

Page 22: Ускоряем загрузку картинок вебсокетами

ITW client

● several streams

● binary data transferring

● local storage using for cache

github.com/yarikos/itw

Page 23: Ускоряем загрузку картинок вебсокетами

example: ITW client

github.com/yarikos/itw

Page 24: Ускоряем загрузку картинок вебсокетами

ITW backend

● proxy between ws and http

● static file server with ws-interface

● with cache

Page 25: Ускоряем загрузку картинок вебсокетами

ITW backend - client interface

ITW Server

outencoder

ITW client

Page 26: Ускоряем загрузку картинок вебсокетами

ITW backend - image sources

ITW Server

inputSTATIC

inputHTTP

WEB

HDD

Page 27: Ускоряем загрузку картинок вебсокетами

example: ITW server

Page 28: Ускоряем загрузку картинок вебсокетами

benchmark, Kiev - Novosibirsk

● 1.3kB +300% .. +400%

● 14.3kB +20% .. +50%

● 46kB -20% .. +20%

Page 29: Ускоряем загрузку картинок вебсокетами

benchmark, Kiev - Kiev

● 1.3kB +200% .. +300%

● 14.3kB +10% .. +30%

● 46kB 0 .. +20%

Page 30: Ускоряем загрузку картинок вебсокетами

leaflet.js + itw

● Kiev - Kiev +20% .. +30%

● Kiev - Novosibirsk 1.5x .. 2x slower

Page 31: Ускоряем загрузку картинок вебсокетами

async is betterHTTP GET

WebSocket

Page 32: Ускоряем загрузку картинок вебсокетами

questions?

http://github.com/yarikos/itwhttp://twitter.com/yarik_is