I have developed a proxy which lets me consume catchup video provided by my ISP as udp unicast m2tp streams through http. For that I am using Sanic.
It is working beautifully yet there is something I cannot explain. Some streams use less than 8% of one cpu core (i7-3770), while other specific ones consume as much as 30%. All the streams are in principle the same and I do not do any processing on them, just read from a udp socket and write to a streamed
sanic.Response, basically this:
import asyncio_dgram import socket from contextlib import closing from Sanic import Sanic, response app = Sanic() MIME = 'video/MP2T' @app.get('/some/url') async def handle_url(request): host = socket.gethostbyname(socket.gethostname()) client_port = 43545 async def my_streaming_fn(response): with closing(await asyncio_dgram.bind((host, client_port))) as stream: while True: data, remote_addr = await stream.recv() await response.write(data) return response.stream(my_streaming_fn, content_type=MIME)
All the streams arrive on a separate vlan, all the ts packets are 1344 bytes (1316 without headers). I see the difference with streams of the same bitrate, even from the same original tv channel.
What I am missing which could explain the huge difference in cpu usage between some and other streams? Any idea?