Why ListenBrainz has been slow this week (and why it wasn’t July all over again)

If you’ve noticed delayed listens, slow imports or other *Brainz sites restarting over the past day or so, here’s what happened, what held up better than last time, and what we’re working on next. You like graphs, so there are lots of graphs.

tl;dr: Another wave of new users and Last.fm imports arrived this week. In July, a similar wave knocked ListenBrainz over for about 10 days. This time, the infrastructure work we’ve done since then let us clear the backlog in about 24 hours. We did hit a new problem that caused repeated restarts of other *Brainz services, which was fixed within a few hours, and it tells us where to focus next.

A quick look back at July

In July, ListenBrainz saw a huge burst of new users, many of them from the BTS ARMY community (welcome, and we’re glad you’re here! Did we mention that our new ED is ARMY and RM stans?). Lots of new users means lots of Last.fm history imports, sometimes 20 years of listens per account, all at once.

We weren’t ready for it. ListenBrainz was effectively unusable, imports slowed to a crawl for about 10 days, and the load took other MetaBrainz services down with it.

The incoming queue during the July burst. Because our services were struggling, listens piled up for a whole week before we could work through them all. Individual queues peaked around 500K listens (the count is tripled on the graph, because we have redundant queues to ensure we never lose any listen you sent us).

What we’ve changed since then

Since July we’ve focused on making the infrastructure absorb sudden bursts instead of falling over:

  • Splitting up services. We decoupled services so we can run several copies (replicas) of each and scale horizontally when traffic spikes.
  • Better connection throughput. More requests and listens can move through the system at the same time.
  • Hunting down slow database queries. A few slow queries were enough to make everything else grind to a halt. We found and fixed them.
  • A new database system and partitioning scheme. This simplified and sped up how listens are ingested.
  • Statistics and recommendation playlists (ongoing). We’re reworking these to handle a much larger user base.

This week’s burst

This week’s wave looked smaller until the weekend. More importantly, we had imports under control within 24 hours, thanks to the changes above.

The incoming queue during this week’s burst. The initial bursts were managed quickly, but over the weekend during our team’s night-time listens queued up with a short peak of 300K listens, and the backlog cleared in a bit over 12 hours instead of 7 days.

Side by side:

July burstThis week
Peak listens per import queue~500K~300K
Time to clear the backlog~7 daysa bit over 12 hours
Overall impactListenBrainz unusable, imports slow for ~10 days, other MetaBrainz services downImports delayed ~1 day, other *Brainz services restarting for a few hours

Zoomed out to the same scale, from mid-June to today, the difference is hard to miss:

What a burst looks like compared to normal traffic

Top: the purple peaks are Last.fm imports, reaching around 100K listens per minute against a baseline of a few thousand. Bottom: the green line shows new listens added, which turns sharply upward when the imports start on the evening of November 18th.

The new problem: restarts elsewhere

This time ListenBrainz itself held up, but on Friday we ran into a new issue that caused other *Brainz services to restart repeatedly. We got it under control within a few hours.

The “Stegosaurus back”: the periodic restarts on November 20th, which ended around 11:15 CET. You can see where it gets its name.

What’s next

This burst showed that the work we put in since July paid off, and it also showed where we’re still weak. Over the next few months our infrastructure priorities are:

  • Making sure a busy ListenBrainz can’t knock over the other *Brainz services, so the problem behind the “Stegosaurus back” doesn’t come back.
  • Finishing the work on statistics and recommendation playlists so they scale with the user base.
  • Continuing to tune ingestion and imports and allow us to scale horizontally on demand, so the next, possibly bigger, burst is a non-event.

Regarding Last.fm, we want to reassure the community that we will continue to support integration and imports from Last.FM to ListenBrainz in the future.

Additionally, if you cannot upgrade your favorite scrobbler, music player or self-hosted library to follow the new API changes, you can point it at our Last.fm-compatible API: https://listenbrainz.readthedocs.io/en/latest/users/api-compat.html

Thanks for your patience, and welcome to everyone who just joined. If you have questions, or ideas about any of the graphs above, come talk to us on the forums, here or chat.

Leave a Reply

Your email address will not be published. Required fields are marked *