66 ms·
WebSockets cost us $1M on our AWS bill
- handfuloflight 2y agoLove the transparency here. Would also love if the same transparency was applied to pricing for their core product. Doesn't appear anywhere on the site.
- lawrenceduk 2y agoIt’s ok, it’s now a million dollars/year cheaper when your renewal comes up! Jokes aside though, some good performance sleuthing there.
- DrammBA 2y agoI use that as a litmus test when deciding whether to use a service: if I can't find a prominently linked pricing page on the homepage, I'm out.
- cosmotic 2y agoWhy decode to then turn around and re-encode?
- ketzo 2y agoI had the same question, but I imagine that the "media pipeline" box with a line that goes directly from "compositor" to "encoder" is probably hiding quite a lot of complexity Recall's offering allows you to get "audio, video, transcripts, and metadata" from video calls -- again, total conjecture, but I imagine they do need to decode into raw format in order to split out all these end-products (and then re-encode for a video recording specifically.)
- pavlov 2y agoReading their product page, it seems like Recall captures meetings on whatever platform their customers are using: Zoom, Teams, Google Meet, etc. Since they don't have API access to all these platforms, the best they can do to capture the A/V streams is simply to join the meeting in a headless browser on a server, then capture the browser's output and re-encode it.
- MrBuddyCasino 2y agoThey‘re already hacking Chromium. If the compressed video data is unavailable in JS, they could change that instead.
- moogly 2y agoThey did what every other startup does: put the PoC in production.
- pavlov 2y agoIf you want to support every meeting platform, you can’t really make any assumptions about the data format. To my knowledge, Zoom’s web client uses a custom codec delivered inside a WASM blob. How would you capture that video data to forward it to your recording system? How do you decode it later? Even if the incoming streams are in a standard format, compositing the meeting as a post-processing operation from raw recorded tracks isn’t simple. Video call participants have gaps and network issues and layer changes, you can’t assume much anything about the samples as you would with typical video files. (Coincidentally this is exactly what I’m working on right now at my job.)
- cosmotic 2y agoAt some point, I'd hope the result of zooms code quickly becomes something that can be hardware decoded. Otherwise the CPU, battery consumption, and energy usage are going to be through the roof.
- pavlov 2y agoThe most common video conferencing codec on WebRTC is VP8, which is not hardware decoded either almost anywhere. Zoom’s own codec must be an efficiency improvement over VP8, which is best described as patent-free leftovers from the back of the fridge. Hardware decoding works best when you have a single stable high bitrate stream with predictable keyframes — something like a 4K video player. Video meetings are not like that. You may have a dozen participant streams, and most of them are suffering from packet loss. Lots of decoder context switching and messy samples is not ideal for typical hardware decoders.
- Szpadel 2y agomy guess is either that video they get use some proprietary encoding format (js might do some magic on the feed) or it's because it's latency optimized stream that consumes a lot of bandwidth
- hipadev23 2y agowhat was the actual cost? cpu?
- cynicalsecurity 2y agoThey are desperately trying to blame anyone except themselves.
- ted_dunning 2y agoYes. CPU costs due to multiple memcpy operations.
- a_t48 2y agoDid they consider iceoryx2? From the outside, it feels like it fits the bill.
- ComputerGuru 2y agoI don't mean to be dismissive, but this would have been caught very early on (in the planning stages) by anyone that had/has experience in system-level development rather than full-stack web js/python development. Quite an expensive lesson for them to learn, even though I'm assuming they do have the talent somewhere on the team if they're able to maintain a fork of Chromium. (I also wouldn't be surprised if they had even more memory copies than they let on, marshalling between the GC-backed JS runtime to the GC-backed Python runtime.) I was coming back to HN to include in my comment a link to various high-performance IPC libraries, but another commenter already beat me linking to iceoryx2 (though of course they'd need to use a python extension). SHM for IPC has been well-understood as the better option for high-bandwidth payloads from the 1990s and is a staple of Win32 application development for communication between services (daemons) and clients (guis).
- Sesse__ 2y agoIt's not even clear why they need a browser in the mix; most of these services have APIs you can use. (Also, why fork Chromium instead of using CEF?)
- dmazzoni 2y ago> It's not even clear why they need a browser in the mix; most of these services have APIs you can use They have APIs to schedule meetings. They don't have APIs that give you access to the compressed video stream.
- Sesse__ 2y agoMany of them do, they're just not something any random person can go and sign up for.
- CharlieDigital 2y ago> I don't mean to be dismissive, but this would have been caught very early on (in the planning stages) by anyone that had/has experience in system-level development rather than full-stack web js/python development Based on their job listing[0], Recall is using Rust on the backend. [0] https://www.workatastartup.com/companies/recall-ai https://www.workatastartup.com/companies/recall-ai
- jgalt212 2y ago> But it turns out that if you IPC 1TB of video per second on AWS it can result in enormous bills when done inefficiently. As a point of comparison, how many TB per second of video does Netflix stream?
- ffsm8 2y agoI don't think that number is as easy to figure out as most people think. Netflix has hardware ISPs can get so they can serve their content without saturating the ISPs lines. There is a statistic floating around that Netflix was responsible for 15% of the global traffic 2022/2023, and YouTube 12%. If that number is real... That'd be a lot more
- CyberDildonics 2y agoActual reality beyond the fake title: "using WebSockets over loopback was ultimately costing us $1M/year in AWS spend" then "and the quest for an efficient high-bandwidth, low-latency IPC" Shared memory. It has been there for 50 years.
- renewiltord 2y agoThat's a good write-up with a standard solution in some other spaces. Shared memory buffers are very fast too. It's interesting to see them being used here. Nice write up. It wasn't what I expected: that they were doing something dumb with API Gateway Websockets. This is actual stuff. Nice.
- OptionOfT 2y agoDid they originally NOT run things on the same machine? Otherwise the WebSocket would be local and incur no cost.
- jgauth 2y agoDid you read the article? It is about the CPU cost of using WebSockets to transfer data over loopback.
- kunwon1 2y agoI read the entire article and that wasn't my takeaway. After reading, I assumed that AWS was (somehow) billing for loopback bandwidth, it wasn't apparent (to me) from the article that CPU costs were the sticking point
- DrammBA 2y ago> We set a goal for ourselves to cut this CPU requirement in half, and thereby cut our cloud compute bill in half. From the article intro before they dive into what exactly is using the CPU.
- magamanlegends 2y agoour websocket traffic is roughly 40% of recall.ai and our bill was $150 USD this month using a high memory VPS
- nemothekid 2y ago>WebSocket would be local and incur no cost. The memcopys are the cost that they were paying, even if it was local.
- ted_dunning 2y agoThe article describes why this isn't the problem. You might enjoy reading it. The basic point is that WebSockets requires that data move across channels that are too general and cause multiple unaligned memory copies. The CPU cost to do the copies was what cost the megabuck, not network transfer costs.
- akira2501 2y ago> A single 1080p raw video frame would be 1080 * 1920 * 1.5 = 3110.4 KB in size They seem to not understand the fundamentals of what they're working on. > Chromium's WebSocket implementation, and the WebSocket spec in general, create some especially bad performance pitfalls. You're doing bulk data transfers into a multiplexed short messaging socket. What exactly did you expect? > However there's no standard interface for transporting data over shared memory. Yes there is. It's called /dev/shm. You can use shared memory like a filesystem, and no, you should not be worried about user/kernel space overhead at this point. It's the obvious solution to your problem. > Instead of the typical two-pointers, we have three pointers in our ring buffer: You can use two back to back mmap(2) calls to create a ringbuffer which avoids this.
- Scaevolus 2y agoIt's pretty funny that they assumed that memory copying was the limiting factor when they're pushing a mere 150MB/s around instead of the various websocket overheads, then jumped right into over-engineering a zero copy ring buffer. I get it, but come on! >50 GB/s of memory bandwidth is common nowadays[1], and will basically never be the bottleneck for 1080P encoding. Zero copy matters when you're doing something exotic, like Netflix pushing dozens of GB/s from a CDN node. [1]: https://lemire.me/blog/2024/01/18/how-much-memory-bandwidth-do-large-amazon-instances-offer/ https://lemire.me/blog/2024/01/18/how-much-memory-bandwidth-...
- anonymous344 2y agowell someone will feel like an idiot after reading your facts. This is why education and experience is important. Not just React/rust course and then you are full stack senior :D
- mlvljr 2y ago[dead]
- didip 2y agoI agree with you. The moment they said shared memory, I was thinking /dev/shm. Lots of programming languages have libraries to /dev/shm already. And since it behaves like filesystem, you can swap it with real filesystem during testing. Very convenient. I am curious if they tried this already or not and if they did, what problems did they encounter?
- Dylan16807 2y agoThe title makes it sound like there was some kind of blowout, but really it was a tool that wasn't the best fit for this job, and they were using twice as much CPU as necessary, nothing crazy.
- deleted 2y ago[deleted]
- hkgjjgjfjfjfjf 2y ago[dead]
- yapyap 2y ago> But it turns out that if you IPC 1TB of video per second on AWS it can result in enormous bills when done inefficiently. that’s surprising to.. almost no one? 1TBPS is nothing to scoff at
- blibble 2y agoin terms of IPC, DDR5 can do about 50GB/s per memory channel assuming you're only shuffling bytes around, on bare metal this would be ~20 DDR5 channels worth or 2 servers (12 channels/server for EPYC) you can get an awful lot of compute these days for not very much money (shipping your code to the compressed video instead of the exact opposite would probably make more sense though)
- pyrolistical 2y agoTerabits vs gigabytes
- blibble 2y agomultiply 50 gigabytes * 20 and tell me what you get pro-tip: it's quite a bit bigger than a terabit
- CyberDildonics 2y agoTerabits vs gigabytes What does this mean? The article says 'TB' which would be terabytes. Terabytes are made out of gigabytes. There is nothing faster than straight memory bandwidth. DDR5 has 64 GB/s max. 12 channels of that is 768 GB/s. Terabytes per second is going to take multiple computers, but it will be a lot less computers if you're using shared memory bandwidth and not some sort of networking loopback.
- punduk 2y ago[flagged]
- turtlebits 2y agoIs this really an AWS issue? Sounds like you were just burning CPU cycles, which is not AWS related. WebSockets makes it sound like it was a data transfer or API gateway cost.
- VWWHFSfQ 2y ago> Is this really an AWS issue? I doubt they would have even noticed this outrageous cost if they were running on bare-metal Xeons or Ryzen colo'd servers. You can rent real 44-core Xeon servers for like, $250/month. So yes, it's an AWS issue.
- JackSlateur 2y agoYou can rent real 44-core Xeon servers for like, $250/month. Where, for instance ?
- Faaak 2y agoHetzner for example. An EPYC 48c (96t) goes for 230 euros
- dilyevsky 2y agoHetzner network is complete dog. They also sell you machines that are long should be EOL’ed. No serious business should be using them
- dijit 2y agoWhat cpu do you think your workload is using on AWS? GCP exposes their cpu models, and they have some Haswell and Broadwell lithographies in service. Thats a 10+ year old part, for those paying attention.
- dilyevsky 2y agoMost of GCP and some AWS instances will migrate to another node when it’s faulty. Also disk is virtual. None of this applies to baremetal hetzner
- londons_explore 2y agoThey are presumably using the GPU for video encoding.... And the GPU for rendering... So they should instead just be hooking into Chromium's GPU process and grabbing the pre-composited tiles from the LayerTreeHostImpl[1] and dealing with those. [1]: https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/layer_tree_host_impl.h;l=203;bpv=1;bpt=1?q=LayerTreeHostImpl&ss=chromium https://source.chromium.org/chromium/chromium/src/+/main:cc/...
- isoprophlex 2y agoYou'd think so but nope, they deliberately run on CPU, as per the article...
- yjftsjthsd-h 2y ago> We do our video processing on the CPU instead of on GPU, as GPU availability on the cloud providers has been patchy in the last few years. I dunno, when we're playing with millions of dollars in costs I hope they're at least regularly evaluating whether they could at least run some of the workload on GPUs for better perf/$.
- londons_explore 2y agoAnd their workload is rendering and video encoding. Using GPU's should have been where they started, even if it limits their choice of cloud providers a little.
- mbb70 2y agoThey are very explicit in the article that they run everything on CPUs.
- orf 2y agoOne of the first parts of the post explains how they are using CPUs only
- deleted 2y ago[deleted]
- cogman10 2y agoThis is such a weird way to do things. Here they have a nicely compressed stream of video data, so they take that stream and... decode it. But they aren't processing the decoded data at the source of the decode, so instead they forward that decoded data, uncompressed(!!), to a different location for processing. Surprisingly, they find out that moving uncompressed video data from one location to another is expensive. So, they compress it later (Don't worry, using a GPU!) At so many levels this is just WTF. Why not forward the compressed video stream? Why not decompress it where you are processing it instead of in the browser? Why are you writing it without any attempt at compression? Even if you want lossless compression there are well known and fast algorithms like flv1 for that purpose. Just weird.
- isoprophlex 2y agoArticle title should have been "our weird design cost us $1M". As it turns out, doing something in Rust does not absolve you of the obligation to actually think about what you are doing.
- dylan604 2y agoTFA opening graph "But it turns out that if you IPC 1TB of video per second on AWS it can result in enormous bills when done inefficiently. "
- rozap 2y agoReally strange. I wonder why they omitted this. Usually you'd leave it compressed until the last possible moment.
- dylan604 2y ago> Usually you'd leave it compressed until the last possible moment. Context matters? As someone working in production/post, we want to keep it uncompressed until the last possible moment. At least as far as no more compression than how it was acquired.
- 2y ago
- dbrower 2y agoHow much did the engineering time to make this optimization cost?
- thadk 2y agoCould Arrow be a part of the shared memory solution in another context?
- remram 2y agoNo, why? > Arrow libraries provide convenient methods for reading and writing columnar file formats
- bauruine 2y agoFWIW: The MTU of the loopback interface on Linux is 64KB by default
- beoberha 2y agoClassic Hacker News getting hung up on the narrative framing. It’s a cool investigation! Nice work guys!
- marcopolo 2y agoMasking in the WebSocket protocol is kind of a funny and sad fix to the problem of intermediaries trying to be smart and helpful, but failing miserably. The linked section of the RFC is worth the read: https://www.rfc-editor.org/rfc/rfc6455#section-10.3 https://www.rfc-editor.org/rfc/rfc6455#section-10.3
- moron4hire 2y agoHow is this a problem of WebSockets and not HTTP in general? The RFC has a link to a document describing the attack, but the link is broken.
- jazzyjackson 2y agoI for one would like to praise the company for sharing their failure, hopefully next time someone Googles "transport video over websocket" theyll find this thread.
- pier25 2y agoWhy were they using websockets to send video in the first place? Was it because they didn't want to use some multicast video server?
- IamLoading 2y agoMy surprise too, whats the issue of webRTC again?
- remram 2y agoSince their overhead is memcpy, I don't see how WebRTC would help.
- dmazzoni 2y agoThey join a 3rd-party meeting using a browser. Then they capture the video from the meeting in Chromium. Then they need to send that captured video to another process for compression and processing. No, WebSockets isn't the most efficient, but there aren't that many options once you're capturing inside a web page.
- dilyevsky 2y agoNot totally sure but they probably extract video via Chrome DevTools Protocol which uses WebSocket as transport.
- trollied 2y ago>In a typical TCP/IP network connected via ethernet, the standard MTU (Maximum Transmission Unit) is 1500 bytes, resulting in a TCP MSS (Maximum Segment Size) of 1448 bytes. This is much smaller than our 3MB+ raw video frames. > Even the theoretical maximum size of a TCP/IP packet, 64k, is much smaller than the data we need to send, so there's no way for us to use TCP/IP without suffering from fragmentation. Just highlights that they do not have enough technical knowledge in house. Should spend the $1m/year saving on hiring some good devs.
- karamanolev 2y agoI fail to see how TCP/IP fragmentation really affects this use case. I don't know why it's mentioned and given that there aren't multiple network devices with different MTUs it will cause issues. Am I right? Is that the lack of technical knowledge you're referring to or am I missing something?
- drowsspa 2y agoSounds weird that apparently they expected to send 3 MB in a single TCP packet
- bcrl 2y agoModern NICs will do that for you via a feature called TSO -- TCP Segmentation Offload. More shocking to me is that anyone would attempt to run network throughput oriented software inside of Chromium. Look at what Cloudflare and Netflix do to get an idea what direction they should really be headed in.
- oefrha 2y agoThey use Chromium (or any other browser) not out of choice but because they have to in order to participate in third party video conference sessions. Of course it’s best to reverse engineer the video conferencing clients and do HTTP requests directly without a headless browser, but I presume they’ve tried that and it’s very difficult, not to mention prone to breaking at any moment. What’s surprising to me is they can’t access the compressed video on the wire and have to send decoded raw video. But presumably they’ve thought about that too.
- cperciva 2y agoWe use atomic operations to update the pointers in a thread-safe manner Are you sure about that? Atomics are not locks, and not all systems have strong memory ordering.
- jpc0 2y ago> ... update the pointers ... Pretty sure ARM and x86 you would be seeing on AWS does have strong memory ordering, and has atomic operations that operate on something the size of a single register...
- cperciva 2y agoGraviton has weaker memory ordering than amd64. I know this because FreeBSD had a ring buffer which was buggy on Graviton...
- Sesse__ 2y agoRust atomics, like C++ atomics, include memory barriers (the programmer chooses how strong, the compiler/CPU is free to give stronger).
- CodesInChaos 2y ago> not all systems have strong memory ordering Atomics require you to explicitly specify a memory ordering for every operation, so the system's memory ordering doesn't really matter. It's still possible to get it wrong, but a lot easier than in (traditional) C.
- reitzensteinm 2y agoIt's still possible to incorrectly use relaxed operations, and have your algorithm only incidentally work because the compiler hasn't reordered them and you're on a CPU with a stronger memory model. But yes, it's an order of magnitude easier to get portability right using the C++/Rust memory model than what came before.
- CyberDildonics 2y ago
- gwbas1c 2y agoClassic story of a startup taking a "good enough" shortcut and then coming back later to optimize. --- I have a similar story: Where I work, we had a cluster of VMs that were always high CPU and a bit of a problem. We had a lot of fire drills where we'd have to bump up the size of the cluster, abort in-progress operations, or some combination of both. Because this cluster of VMs was doing batch processing that the founder believed should be CPU intense, everyone just assumed that increasing load came with increasing customer size; and that this was just an annoyance that we could get to after we made one more feature. But, at one point the bean counters pointed out that we spent disproportionately more on cloud than a normal business did. After one round of combining different VM clusters (that really didn't need to be separate servers), I decided that I could take some time to hook up this very CPU intense cluster up to a profiler. I thought I was going to be in for a 1-2 week project and would follow a few worms. Instead, the CPU load was because we were constantly loading an entire table, that we never deleted from, into the application's process. The table had transient data that should only last a few hours at most. I quickly deleted almost a decade's worth of obsolete data from the table. After about 15 minutes, CPU usage for this cluster dropped to almost nothing. The next day we made the VM cluster a fraction of its size, and in the next release, we got rid of the cluster and merged the functionality into another cluster. I also made a pull request that introduced a simple filter to the query to only load 3 days of data; and then introduced a background operation to clean out the table periodically.
- alsetmusic 2y agoAs much as you can say (perhaps not hard numbers, but as a percentage), what was the savings to the bottom line / cloud costs?
- gwbas1c 2y agoProbably ~5% of cloud costs. Combined with the prior round of optimizations, it was substantial. I was really disappointed when my wife couldn't get the night off from work when the company took everyone out to a fancy steak house.
- 2y ago
- wiml 2y ago> One complicating factor here is that raw video is surprisingly high bandwidth. It's weird to be living in a world where this is a surprise but here we are. Nice write up though. Web sockets has a number of nonsensical design decisions, but I wouldn't have expected that this is the one that would be chewing up all your cpu.
- handfuloflight 2y ago> It's weird to be living in a world where this is a surprise but here we are. I think it's because the cost of it is so abstracted away with free streaming video all across the web. Once you take a look at the egress and ingress sides you realize how quickly it adds up.
- arccy 2y agoI think it's just rare for a lot of people to be handling raw video. Most people interact with highly efficient (lossy) codecs on the web.
- adastra22 2y agoEven compressed video is massive data though.
- lillecarl 2y agoI was surprised when calculating and sizing the shared memory for my Gaming VM for use with "Looking-Glass". At 165hz 2k HDR it's many gigabytes per second, that's why HDMI and DisplayPort is specced really high
- jazzyjackson 2y agoI'd still like to get a looking glass. What did you end up with?
- sensanaty 2y agoI always knew video was "expensive", but my mark for what expensive meant was a good few orders of magnitude off when I researched the topic for a personal project. I can easily imagine the author being in a similar boat, knowing that it isn't cheap, but then not realizing that expensive in this context truly does mean expensive until they actually started seeing the associated costs.
- IX-103 2y agoChromium already has a zero-copy IPC mechanism that uses shared memory built-in. It's called Mojo. That's how the various browser processes talk to each other. They could just have passed mojo::BigBuffer messages to their custom.process and not had to worry about platform-specific code. But writing a custom ring buffer implementation is also nice, I suppose...
- doctorpangloss 2y agoThe best way to find out something valuable is to be wrong on the Internet. Next time, bill them $10k for this secret!
- cyberax 2y agoEgress fees strike again.
- ted_dunning 2y agoNo. That isn't what they said. Read the article.
- sfink 2y ago...and this is why I will never start a successful business. The initial approach was shipping raw video over a WebSocket. I could not imagine putting something like that together and selling it. When your first computer came with 64KB in your entire machine, some of which you can't use at all and some you can't use without bank switching tricks, it's really really hard to even conceive of that architecture as a possibility. It's a testament to the power of today's hardware that it worked at all. And yet, it did work, and it served as the basis for a successful product. They presumably made money from it. The inefficiency sounds like it didn't get in the way of developing and iterating on the rest of the product. I can't do it. Premature optimization may be the root of all evil, but I can't work without having some sense for how much data is involved and how much moving or copying is happening to it. That sense would make me immediately reject that approach. I'd go off over-architecting something else before launching, and somebody would get impatient and want their money back.
- ketzo 2y agoIf you can feel that way about your work, but still understand that this approach has its own benefits, you're probably a really good person to hire when a startup does hit scaling issues from their crappy original code! Knowing thyself is a superpower all its own; we need people to write scrappy code to validate a business idea, and we need people who look at code with disgust, throw it out, and write something 100x as efficient.
- dmazzoni 2y agoThe initial approach was shipping raw video over a WebSocket...between two processes running on the same machine. That doesn't sound like a ridiculous idea to me. How else would you get video data out of a sandboxed Chromium process?
- sfink 2y agoShort answer: raw video is big. With my mindset, you have a gigantic chunk of data. Especially if you're recording multiple streams per machine. The immediate thought is that you want to avoid copying as much as possible. If you really, really have to, you can copy it once. Maybe even twice, though before moving from 1 to 2 copies you should spend some time thinking about whether it's possible to move from 1 to 0, or never materializing the full data at all (i.e., keep it compressed, which could apply here but only as an optimization for certain video applications and so is irrelevant to the bootstrapping phase). WebSockets take your giant chunk of data and squeeze it through a straw. How many times does each byte get copied in the process? I don't know, but probably more than twice. Even worse, it's going to process it in chunks, so you're going to have per-chunk overhead (maybe including a context switch?) that is O(number of chunks in a giant data set). But the application fundamentally requires squishing that giant data back down again, which immediately implies moving the computation to the data. I would want to experiment with a wasm-compiled video compressor (remember, we already have the no GPU constraint, so it's ok to light the CPU on fire), and then get compressed video out of the sandbox. WebSockets don't seem unreasonable for that -- they probably cost a factor of 2-4 over the raw data size, but once you've gained an order of magnitude from the compression, that's in the land of engineering tradeoffs. The bigger concern is dropping frames by combining the frame generation and reading with the compression, though I think you could probably use a Web Worker and SharedArrayBuffers to put those on different cores. But I'm wrong. The data isn't so large that the brute force approach wouldn't work at all. My version would take longer to get up and running, which means they couldn't move on to the rest of the system.
- apitman 2y agoI've been toying around with a design for a real-time chat protocol, and was recently in a debate of WebSockets vs HTTP long polling. This should give me some nice ammunition.
- pavlov 2y agoNo, this story is about interprocess communication on a single computer, it has practically nothing to do with WebSockets vs something else over an IP network.
- apitman 2y agoWhy do they claim their profile data showed that WebSocket fragmentation and masking were the hot spots?
- pavlov 2y agoBecause they were sending so much data to another process over the Websocket. An uncompressed 1920*1080 30fps RGB stream is 178 megabytes / second. (This is 99% likely what they were capturing from the headless browser, although maybe at a lower frame rate - you don’t need full 30 for a meeting capture.) In comparison, a standard Netflix HD stream is around 1.5 megabits / s, so 0.19 megabytes. The uncompressed stream is almost a thousand times larger. At that rate, the Websocket overhead starts having an impact.
- apitman 2y agoIt should still have the same impact at scale, right? ie if I had a server handling enough WebSocket connections to be at 90% CPU usage, switching to a protocol with lower overhead should reduce the usage and thus save me money. This is of course assuming the system isn't io bound.
- calibas 2y agoWhy use Chromium at all? Isn't it just decoding video and sending it over a websocket?
- devit 2y agoThe problem seems to be that they are decompressing video in Chromium and then sending the uncompressed video somewhere else. A more reasonable approach would be to have Chromium save the original compressed video to disk, and then use ffmpeg or similar to reencode if needed. Even better not use Chromium at all.
- ec109685 2y agoThey’re scraping video from VC services, so only have access to the frame buffer.
- devit 2y agoPresumably those services use Chromium codecs and perhaps standard WebRTC, so they have access to the encoded data stream as well (via JavaScript injection or patching Chromium to dump the data).
- ahmetozer 2y agoAt least 1m in a year not week
- austin-cheney 2y agoWe read through the WebSocket RFC, and Chromium's WebSocket implementation, dug through our profile data, and discovered two primary causes of slowness: fragmentation, and masking. So they are only half way correct about masking. The RFC does mandate that client to server communication be masked. That is only enforced by web browsers. If the client is absolutely anything else just ignore masking. Since the RFC requires a bit to identify if a message is masked and that bit is in no way associated to the client/server role identity of the communication there is no way to really mandate enforcement. So, just don't mask messages and nothing will break. Fragmentation is completely unavoidable though. The RFC does allow for messages to be fragmented at custom lengths in the protocol itself, and that is avoidable. However, TLS imposes message fragmentation. In some run times messages sent at too high a frequency will be concatenated and that requires fragmentation by message length at the receiving end. Firefox sometimes sends frame headers detached from their frame bodies, which is another form of fragmentation. You have to account for all that fragmentation from outside the protocol and it is very slow. In my own implementation receiving messages took just under 11x longer to process than sending messages on a burst of 10 million messages largely irrespective of message body length. Even after that slowness WebSockets in my WebSocket implementation proved to be almost 8x faster than HTTP 1 in real world full-duplex use on a large application.
- simoncion 2y ago> However, TLS imposes message fragmentation. If one is doing websockets on the local machine (or any other trusted network) and one has performance concerns, one should maybe consider not doing TLS. If the websocket standard demands TLS, then I guess getting to not do that is would be another benefit of not using a major-web-browser-provided implementation.
- mlhpdx 2y agoIt seems like UDP would be a valid option.
- h4ck_th3_pl4n3t 2y agoThe problem is not on network level. The problem is that the developers behind this way of streaming video data seem to have no idea of how video codecs work. If they are in control of the headless chromium instances, the video streams, and the receiving backend of that video stream...why not simply use RDP or a similar video streaming protocol that is made exactly for this purpose? This whole post reads like an article from a web dev that is totally over their head, trying to implement something that they didn't take the time to even think about. Arguing with TCP fragmentation when that is not even an issue, and trying to use a TCP stream when that is literally the worst thing you can do in that situation because of roundtrip costs. But I guess that there is no JS API for that, so it's outside the development scope? Can't imagine any reason not to use a much more efficient video codec here other than this running in node.js, potentially missing offscreen canvas/buffer APIs and C encoding libraries that you could use for that. I would not want to work at this company, if this is how they develop software. Must be horribly rushed prototypical code, everywhere.
- doctorpangloss 2y agoIt’s alright. It is difficult to say, I’ve never used the product. They don’t describe what it is they are trying to do. If you want to pipe a Zoom call to a Python process it’s complicated. Everything else that uses WebRTC, I suppose Python should generate the candidates, and the fake browser client hands over the Python process’s candidates instead of its own. It could use the most basic bindings to libwebrtc. If the bulk of their app is JavaScript, they ought to inject a web worker and use encoded transforms. But I don’t know though.
- dmazzoni 2y agoTheir business is joining meetings from 7 different platforms (Zoom, Meet, WebEx, etc.) and capturing the video. They don't have control of the incoming video format. They don't even have access to the incoming video data, because they're not using an API. They're joining the meeting using a real browser, and capturing the video. Is it an ugly hack? Maybe. But it's also a pretty robust one, because they're not dependent on an API that might break or reverse-engineering a protocol that might change. They're a bit dependent on the frontend, but that changes rarely and it's super easy to adapt when it does change.
- nutanc 2y agoA little off topic, but if you need a bot for a meeting, do you even need a meeting?
- mannyv 2y agoWhy don't they just write the meeting output to hls, then use the hls as input to the rest of their stuff? Cheaper and more straightforward. Their discussion of fragmentation shows they are clueless as to the details of the stack. All that shit is basically irrelevant.
- dmazzoni 2y ago> Why don't they just write the meeting output to hls They're capturing video from inside a Chromium process. How exactly do you expect to send the raw captured video frames to hls? Are you proposing implementing the HLS server inside a web process?
- mannyv 2y agoNo, what I'm saying is pipe the video output to an HLS encoder. HLS live will rewrite the m3u8 as more segments come in. In fact, they can render the audio into its own m3u8 and use that as input for their transcriber, saving even more bandwidth/data transfer/etc. Since it's coming from a headless process, they can just pipe it into ffmpeg, which is probably what they're using on the back-end anyway. Send the output to a file, then copy those to s3 as they're generated. And you can drop the frame rate and bitrate on that while you're at it, saving time and latency. It's really not rocket science. You just have to understand your problem domain more better. Shipping uncompressed video around is ridiculous, unless you're doing video editing. And even then you should use low-res copies and just push around EDLs until you need to render (unless you need high-res to see something). Given that they're doing all that work, they might as well try to get an HLS encoder running in chrome. There just was an mp3 codec in web assembly on HN, so an HLS live encoder may not be too hard. I mean, if they were blowing a million because of their bad design they could blow another million building a browser-based HLS encoder.
- pyeri 2y agoWebSockets has become popular only due to this "instant" mindset. IRL, only a handful of messages or notifications need a truly real-time priority such as Bank OTPs, transaction notifs, etc. Others can wait for a few seconds, and other architectures like middleware, client-side AJAX polling, etc. could be both cheaper and sufficient there.
- algobro 2y agoGood flex. These days access to capital is attractive for talent.
- nottorp 2y agoWait but you can hire cheap kids to do it in javascript with web 5.0 technologies. Or pay a little more and have it done with web 7.0 tech. Always. Always ?!? Article summary: if you're moving a lot of data, your protocol's structure and overhead matters. A lot.
- nicwolff 2y agoThis is very confusing naming: > write pointer: the next address to write to OK > peek pointer: the address of the next frame to read > read pointer: the address where data can be overwritten What? If the "write pointer" is the "the next address to write to" then the "read pointer" had better be "the next address to read from". The "peek pointer" should be the "read pointer", and the pointer to the end of the free sector should be the "stop pointer" or "unfreed pointer" or "in-use pointer" or literally anything else. Even "third pointer" would be less confusing!
- jjeryini 2y agoYou mentioned in the article that you went searching for an alternative to WebSocket for transporting the raw decoded video out of Chromium's Javascript environment. Have you also considered WebTransport?