New Year, New Challenges (Patreon)
Content
I think Futureporn's biggest shortcoming is performance. Without a traditional Content Delivery Network (CDN), videos on Futureporn often load slowly.
A few weeks ago a site viewer reached out to me with some questions. One of those questions was how much do I pay to run it? My answer was $130 a month, to which they replied, "that's a lot!"
They went on to suggest a hosting provider which I promptly checked out. I'm all for saving money, and any opportunity to save money in one area means I can reallocate funds to improving things in another.
I checked out the suggested hosting provider and saw a fantastic deal. A dedicated server with an 8 core CPU, 32GB RAM, 3TB storage, all for $40 a month. Normally I'm used to paying $75 a month for 3TB storage by itself, and that's not even including a server to access said storage!
It seemed too good to be true, but my dream of improving Futureporn got the best of me. I immediately rented the dedicated server and ran my provisioning scripts to configure the server to run as an IPFS cluster peer, and public IPFS gateway.
Things were looking great. I had an IPFS cluster with a total of 2 peers, each communicating with the other and synchronizing their 2TB pinsets. This was a slow process, but every day I would check IPFS metrics, and see that the pin size was growing, and the queue size was shrinking.
As soon as I was able, I configured the frontend website to start sending traffic to my IPFS gateway rather than using the free public gateway which often becomes overloaded.
Videos on Futureporn seemed to load faster than ever. I could even seek to a different timestamp in the video and there was minimal buffering. A dedicated server is great! I was very happy about about that, and checked off one of the goals on futureporn.net/goals
It took a few days, then things went south. CPU usage on the dedicated server jumped up to 600-800%, meaning there was 6 to 8 times more work than the CPU could handle immediately.
Videos had lengthy buffer times again. Pin synchronization between cluster peers slowed down, and eventually came to a halt.
What was going on with the server? Why was it going so hard and delivering so little?
I spent a couple days reading IPFS cluster documentation. I would tweak it's configuration, restart the IPFS instance, and watch a VOD to gauge performance. I did this a number of times, each trying a different configuration, and didn't see any performance improvement.
Eventually I checked disk usage out of curiosity. "How big is the IPFS block store?" I wondered.
To my horror, the disk usage was only 100GB. It had drastically shrank!
I went to my config files and furiously dug around. Was garbage collection culling files it thinks are unused? Is it running too often?
Nothing in the config files seemed like it could do the damage that had be done, which led me to look elsewhere. Eventually I reviewed my init script for the IPFS daemon, and saw the following Pre-start script
ExecStartPre=rm -rf /home/ipfs/.ipfs/blocks/ && sync
Oh my god, it was my fault! Baked into my service script is a pre-start command which forcefully deletes everything stored in IPFS! It runs every time I restart the IPFS daemon!
Why did I do this? This seems insane!
I looked through my notes and it seemed less insane for the time when I implemented the ExecStartPre command.
I did that months ago, before I was running an IPFS cluster. At the time, I had low-spec instances with tiny disk sizes. Only 30-50GB for the OS and all the files I was working with. These were usually worker instances that would capture a VOD, upload to a 3rd party pinning service, and after that, have no use for IPFS files locally.
In order to keep their disks from filling to capacity, I implemented that pre-start command which cleared all IPFS blocks.
When I set up an IPFS cluster that relies on maintaining important blocks, I did a lot of copy-pasting of configuration files and init scripts to save time. I did not remember the dangerous ExecStartPre.
Because cluster instances had to re-pin everything every time they restarted, serve gateway requests for both local and non-local content, the demand on my server had been extreme.
I received an e-mail from the hosting provider a few days later informing me that my server had been throttled from 1000Mbps to 100Mbps.
This came as a blow, because I was just getting started with this hosting provider, and had high hopes for finally being able to run an IPFS gateway and improve the user experience.
It's a big bummer, and a reminder that bandwidth is not free.
I've learned from this failure, and I know that going forward I'm now more equipped to running a successful IPFS gateway. Not that this is going to happen anytime soon, but when it does, I'll be ready.
One of the problems I saw with runnng an IPFS gateway as a CDN is that the gateway needs to have the content locally pinned in order to be fast. The ExecStartPre command prevented that from happening, and required that the gateway fetch content from the IPFS network that it didn't have on hand.
I have been blessed by others reaching out to me and seeing if they can volunteer some of their resources towards the Futureporn IPFS cluster. It's been a great help to have other people going through the process of setting up a follower peer, running into issues, and finding shortcomings in my configurations.
I've found a number of issues with my setup following hours of troubleshooting why things are not working as expected. The more I learn about IPFS, the more I realize how complex it really is. I'm often questioning whether or not Protocol Labs, the company behind IPFS is going to be able to realize their goals. It's just so complex with so many moving parts, it's really a wonder that it works at all!
I'm hopeful though. Just like with my own progress learning IPFS and improving slowly, I'm seeing the same in IPFS. For instance, IPFS v0.17.0 enabled a ResourceManager by default, which is designed to prevent denial of service (DoS) attacks from overwhelming incoming requests.
ResourceManager is a great feature, but going from v0.16.0 where ResourceManager was disabled by default, to v0.17.0 where it's enabled, it ran me for a loop. I saw so many error messages in the console stating that incoming connections were maxxed out. I was not used to seeing that and at first didn't know what to do about it.
During the moments when I was seeing high CPU utilization, I thought back to years ago when I was running a popular Flash games website. The site would go down and I had no idea why. I blamed the software. Later I learned that my site was overloaded during school hours, to the point where memory was exhausted and MySQL would crash.
Problems like these occurred because I did not have a good overview of system health. The same thing is happening today. I don't have a good overview of system health, and that's something I want to improve.
This brings me to stats. What I do know is that Futureporn has been receiving 22,000+ visits every week.
This is challenging going forward because I think I have to retire the IPFS gateway once again. This is attempt #2, and each time I've ran into the issue of running out of bandwidth and not having the budget to buy more.
I've learned so much though. I'm trudging forward, and learning every time I fail. Failure is good for growth!
This brings me to what I've been working on as we've started the new year. I've implemented a bunch of new stuff, which may or may not have been noticeable.
I improved Futureporn's Lighthouse score. Lighthouse is a performance benchmark tool which is built into Chromium-based browsers. Scores are graded in the categories of Performance, Accessibility, Best Practices, and Search Engine Optimization.
I added pagination to the front page to improve load times. I also added avif optimized images, and achieved a 99 Performance score in Lighthouse. Thumbnail images were later removed due to seeing HTTP 429 (Too Many Request) errors from the IPFS gateway which would occur when loading all the images at once. This is something that is going to take more thought to implement elegantly, and I want to revisit at a later date.
For now, there are other issues I think are more pressing. The first of which I want to bring up is HumanOps. HumanOps is an ideology that Humans are more important than the technology. Humans run the technology, and when the human is tired, stressed, overworked, the technology starts to fail.
The full HumanOps mantra can be found at https://gist.github.com/morekid/b0d7b2571fdba88f809bc48b0b7d4762 and you can check it out if that sounds interesting. The takeaway for me is that I am often overworking myself and losing sleep because of demanding manual tasks. These tasks could be automated, but they are not, and I am suffering. It becomes a viscous cycle of burnout and being too tired to address the challenges of fixing the root causes of said burnout.
This brings me to what I'm focusing on for the second half of January, and first half of February. Issue #14 "VOD Publishing is not automatic" https://github.com/insanity54/futureporn/issues/14 , an issue that I created on Jan 12, 2022. It's been over a year now, and I'm ready to implement a solution and fix the problem so I can sleep at night.
Here are a few more things I've worked on lately. I implemented a status page, which shows ongoing service disruptions. It uses the excellent Upptime, an open source tool for tracking and handling outages.
Recent failures
2023-01-01 -- missed start of stream and only recorded 240p. Failure due to lack of manual preparation, lack of automation, and forgetting to configure stream quality to "best" in an update to my capture software.
2023-01-05 -- capture instance failed mid-way due to disk being full. Backup capture instance was pegged at 100% and unresponsive
Priorities
Fix VOD publishing is not automatic
One of my original goals was to be the first service to post Melody's VOD. I want to be faster than Melody herself. Maybe that's an easy thing, but I want to be faster than any human (or AI.) I can only do that if things are automatic and aren't constantly falling apart. I've been making lots of progress towards this goal over the past month.
I've improved my capture software with signalling capability, so it automatically notifies the rest of the system that it is recording. Additionally, the recorder can be programmatically started by another system component.
Fix sometimes start of stream is missed
This issue comes up again and again. The reason it happens is because my recorder software is designed to be courteous with network requests to CB. Every 10 minutes or so, it checks to see if a ProjektMelody stream is live. If it is, it starts recording. If not, it tries again in 10 minutes. If a Mel stream is started 2 minutes after a try, that's 8 minutes of stream that get missed.
This issue bothers me A LOT when it happens, because the whole point of archiving is to archive as much as possible. To miss the start of stream is a failure, not a success.
I've been working on overcoming this issue by reverse engineering Chaturbate's real-time event code. I spent a good week going through the developer console, watching what network requests take place, and debugging minified code to see what specific javascript functions are doing.
I'm confident that I will soon be able to tap into Chaturbate's undocumented APIs to be notified exactly when a stream is starting. using this information and the signalling capabilities I mentioned earlier, I will be able to signal to the capture instance that now is the time to record, quit waiting for a timeout and instead just record now.
This brings up a side-project idea I've had in the back of my mind for some time. Better Chaturbate. Kinda like how FrankerFacez, BTTV and 7tv improve the Twitch experience, I would love to create an alternative chat client for Chaturbate which fixes every annoyance that exists in the exiting CB chat. I think I can do it with what I've learned, but again that's another project that can take away from improving Futureporn, so I won't think too hard on that for now.
I have a difficult time knowing what is going wrong when it is going wrong. To know if I'm ready to capture a stream, I open a remote terminal to individual capture instances and run a command to see if the capture softare is running, and another command to check if there is enough free space.
These checks are predictable, routine, and can be automated. Instead of manually checking to see if things are good, I can automatically be notified when things are not.
There are lots of little tweaks here and there that I plan to make, to improve the HumanOps experience.
That's all I got for this month. Let me know if you have any thoughts, and thank you so much for your support!