Some Bits: Nelson's log

28 posts about league-of-legends

Logs of Lag outage

Oh boy did I screw up. Back on September 1 I pushed a tiny change to Logs of Lag, an old service I still run for League of Legends players. It was such a simple change, just adding an HTML link, so I didn’t test it carefully. Turns out I made that change on top of the master branch which had some other changes I’d committed but never tested or deployed back in 2015, and that new-but-old code didn’t work. The site’s been broken for 7 weeks now and I only found out when a user wrote me.

I love this commit comment past-me wrote:

Potentially breaking change: webapp use new stats. This change has not been tested manually, hence the warning in deploy.sh

I did read the commit log before pushing again, but apparently I didn’t read back far enough. Also I didn’t use my deploy script to deploy the server. Talk about shooting yourself in the foot. I even have a tiny bit of monitoring on the service but it didn’t show this kind of error, not that I pay attention to the monitor anyway.

The real problem is that I’ve abandoned this project; I haven’t done real development on it in 4 years. It’s kinda broken now too as the file format the code parsers has changed over time and I haven’t kept up. I’m now 100% fed up with League of Legends and Riot Games, given how sexist and awful that company is. So I have no motivation to do more. But the tool is still useful so I’ve tried to keep it online. (Past me did one thing right: the site is mostly just running static files, so it’s not hard to keep running.)

The site doesn’t get a lot of usage, my estimate last year was 50-100 unique users a day with about ~450 uses of the tool a day. Here’s a graph of the rate of usage; you can see an organic falloff over the whole year, then it falls sharply Sep 1 when I broke the site. I wonder if it will recover.

logsoflag2-year.png

Putting lolslackbot on the back burner

I’ve decided to stop working on lolslackbot, my social project for League of Legends players who use Slack or Discord. I wrote it originally for a few friends, then slowly expanded it to a few hundred users. But I’ve never put the work in to make it a consumer product and now am not motivated to do it.

The main feature missing is any sort of web interface so people could sign up for themselves. I’ve been maintaining it by hand with database update scripts, doing ~30 minutes of one-off work every few weeks instead of one focussed month-long engineering project. This blog is full of bold plans to port the whole thing to Django and get going on a web interface, but I never did it. Too much product work I don’t really know how to do well, designing interactive web UI. Hell, I don’t even have a proper name for the project.

Also some deeper technical problems. The Django port seems doable but requires database schema changes, specifically in how many-to-many relations work. And I got part of my core schema wrong, an assumption that an individual only belongs to one group. Fixing that would require redoing pretty much all the tests and half the business logic. Also at some point I’d have to migrate from sqlite to Postgres and that doesn’t sound like fun at all. In retrospect it’s too bad I didn’t start with Postgres+Django, but that seemed complicated at the beginning when I was thinking of this as just a cron job.

My real reason for lack of enthusiasm is the market. I like games and I like the idea of making game playing more social. But League of Legends is a hard community to build humble tools for. Most of the energy there is to highly polished and well marketed sites like LolKing and I’m just not that ambitious. There’s not much money in it (Riot’s API requires you don’t charge for services) and not a lot of love either. Me and my gaming buddies are on a bit of a LoL break too, which makes it harder to stay personally motivated. I’m also bummed that Riot hasn’t done anything more with Clubs, their social feature, my hope was to springboard off of that to build out the bot.

I did get some data from the last user population of Learning Fives, a cohort of ~80 people playing games together for a few weeks. 50% said they found it useful, 20% said it wasn’t, and 30% didn’t know what it was (despite seeing it in their channel). Not sure what conclusion to draw from that.

Anyway it’s a weight off my mind to just say I’m not going to do further work on this, at least for now. Truthfully my mind is on political work right now, I’d really like to do some sort of progressive activism combining data processing and GIS. (I’m following Mike’s work on redistricting closely.) To the extent I do anything for games it’s about time to revisit Logs of Lag, which 2.5 years later is still running just fine and uniquely useful. But I have some bugs to fix and maybe some improvements to make.

 

League of Legends server IPs

Just writing this down so I don’t lose it. I haven’t verified these. But most of the old lists I’ve seen are no longer valid since Riot started doing its own peering.

  • NA - ping 104.160.131.3
  • EUW - ping 104.160.141.3
  • EUNE - ping 104.160.142.3
  • OCE - ping 104.160.156.1
  • LAN - ping 104.160.136.3

Source is this Reddit discussion about yet another ping checker. I wish Riot would build a small network diagnostic into the client, before a game starts. Many of these third party tools don’t measure round trip time correctly and none that I’ve seen measure packet loss.

Also I was curious so I just did an mtr to the NA address. Average response to the end is 92ms, which is about the same number the league reports as ping. Standard deviation is 12ms, best/worst is 73/140. That’s with ICMP probes, I don’t get responses from UDP probes.

League of Legends rank distribution over time

Just finished a small longitudinal data project. Not real happy with how it turned out, but figured I should document it anyway. Frustrated it doesn’t look better, also that it didn’t get more attention.

Here’s the deliverable: a Reddit post. It’s a visualization of rank inflation in League of Legends over the course of the last year, Season 6. I collected the data by hand out of curiosity. The resulting visualization more or less confirms what people who pay attention already knew; there is inflation. Only 15 upvotes which is crappy engagement for something I spent several hours on.

7mmsnc2

I tinkered with the visualization for awhile. The colors are meaningful, they represent Bronze / Silver / Gold / Platinum to folks who play the game. (There’s also White for Diamond+). There’s 5 divisions within each tier, that’s the black lines. And then some ugly caption text because I wanted to condense the whole thing down to a single shareable image.

I produced it using iPython, Pandas, and matplotlib. I really like Pandas’ abstraction of a DataFrame, it’s a very powerful tool for working for a matrix of numbers. Even so I have a lot of data massaging code to get from my original spreadsheet to a clean list of numbers. Deleting extra rows, transposing rows/columns, converting “93%” to 0.93, etc etc.

I really don’t like matplotlib. I’ll paste my graph generation code below, it’s super ugly. There’s like seven ways to set options. Flags passed to the Pandas plot() function, functions called on the global matplotlib object, functions called on the global pyplot object, functions called on the axis objects, two different ways to modify RC parameters, etc etc. Just a mess. Maybe this is my ignorance though and there’s a way to simplify / rationalize it all.

# Plot
plt.style.use('seaborn-whitegrid')
matplotlib.rc('axes', grid=True)
matplotlib.rc('grid', color='w')
matplotlib.rcParams['font.family'] = ['Liberation Sans']

# Filled area for the tiers
ax = tdf.plot(
    kind='area', stacked=False,
    figsize=(10, 6),
    legend=False,
    linewidth=0,
    alpha=1.0,
    color=('#ffffff', '#87fffd', '#ffdb57', '#dce2f2', '#b2a07e'))
ax.set_yticks(numpy.arange(25,100.01,25))
ax.yaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter('%.0f%%'))

# Lines for every division
df.plot(ax = ax, legend=False, color='k', linewidth=0.5)

# Configure the chart a bit more
ax.set_axisbelow(False)
plt.title('Season 6 distribution of ranks in NA')
plt.text(0, -35, '''There is a general trend of rank inflation...''',
        linespacing=1.4, size=12)

Documenting obscure bugs helps!

Had a real pleasure today; someone found a description of a League of Legends networking problem I wrote up a year ago and it gave him the clue to fix a problem he was having. (Long story short; specific actions in the game cause bursts of high network traffic, which can trigger lag or disconnects.)

I spend a lot of time writing up details of bugs and software problems. I do this partly for clarity, writing it up is a way to make sure I really understand the problem. I also do it so I can find my notes later in case I have a similar problem. And finally I put those descriptions online in case they help other people. And about once a year, they do!

 

League of Legends stats: some findings

I’ve been noodling with some League of Legends data as an excuse to learn more data analysis tech. I’ve blogged about the software, here’s the actual results I found.

League of Legends is a huge game, some 100M a month playing 1M+ games a day. And the data for those games is readily available. I took a look at third party summaries of game statistics from champion.gg and na.op.gg and tried to divine some meaning. The dataset mostly is for ranked games by Platinum+ skilled players in North America for patch 6.17. But I also looked at players of different skill and trends across game patches.

The most interesting conclusion I found was that some champions win much more in the hands of skilled players. Nidalee, for instance, has a 45% win rate in Silver but a 54% win rate in Diamond. That’s not exactly a surprise, she’s known to have a high skill cap, but it’s good to see hard data. And there are surprises; I would not have guessed Pantheon also was highly improved or that Dr. Mundo suffered at higher skill levels.

Despite looking, mostly I didn’t find any unusual trends or big shifts in the game over patches. To me that’s a testament to the quality of the game, in particular Riot’s game balance team.

Below find some analysis and graphs. I’ve put my notebook output online for viewing here:

Basic stats for patch 6.17

The first thing I did was look at the basic champion.gg stats for patch 6.17. Each row in my dataset is one summary line for all players of a champion in a role. For instance Nami / Support. Note there’s a bit of bias here; champion.gg omits rare cases like Nami / Jungle.

There’s relatively little diversity in ADC and Support champions. Simple result: there are only 17 regularly played ADC champions and 25 Supports. There’s ~50 champions played Top/Middle/Jungle. This fact skews a lot of my later statistics, particularly with the ADC pool where a single champion (Lucian) dominates with a 32% play percentage. The top mid, by contrast, is Ahri with only 13%.

download (1).png

Players generally don’t pick champions with higher win rates. This surprised me a bit; I thought there’d be a clear bias towards the OP champs. There isn’t.

download.png

Players do tend to win more on champions they have more experience with. No big surprise here, but more games = more wins. The stat “experience” here is average games played on that champion. (It’s in the champion.gg dataset, but not displayed on the website.) The correlation coefficient is +0.24 with a p value of 0.0005, which seems likely to be significant to me. The causation is less clear. For example Galio-Top players have an average of 107 games on the champ and a 55% win rate. Do people win on Galio because they play him a lot, or do they play him a lot because they win? (Or in the specific case of Galio; do relatively few people play him but the ones who do are really good?)

download.png

Stats for players of different skills from na.op.gg

I was curious how these statistics varied by tier, so I went to na.op.gg and downloaded stats for players at all skill levels. I mostly focussed on Silver through Diamond, since those are the most “normal” player populations. This data is for the month of Aug 15 – Sep 15 2016 and spans patch 6.17 and 6.18.

Some champions have much higher win rates at higher tiers. This result is the most interesting I’ve found. I feel like each player at the extremes has a story. I’m not surprised that Nidalee’s win rate goes up 9.37% from Silver to Diamond; she’s hard to play well and so presumably does better in the hands of a skilled player. Aurelion Sol goes up 5.8%, maybe because he depends on skilled teammates? But why does Pantheon go up 7.5%? He seems so simple! I’m guessing Aatrox and Garen do worse in higher tiers because players know how to exploit their weaknesses. And Amumu’s 4.1% drop may be as simple as Diamond players being less vulnerable to Amumu cheese. But there’s more to say here and I’d like to develop this data further. Here’s the 10 most improved and 10 who suffer the most.

Screen Shot 2016-09-21 at 4.32.54 PM.png

Some champs are significantly more popular at higher tiers. The companion result to win rates; what about pick rates by tier? Janna is the most more frequently picked, she goes from 0.8% to 2.9%. (As a frequent Janna player my theory is she is much more rewarding to play when your team is more skilled.) Leona drops from 1.6% to 0.6%. The ADC champion pool attenuates at higher tiers too; Lucian dominates and Jinx drops off, for instance.

Screen Shot 2016-09-21 at 4.37.11 PM.png

Silver-to-Diamond win rate is correlated with Silver-to-Diamond pick rate. In the previous section I reported that for Platinum players, win rate is not correlated with pick rate. However the champs that have the most improvement rate from Silver-to-Diamond also tend to have higher pick rates from Silver-to-Diamond. This suggests that higher tier players are picking champions that have more impact at their skill level. Well maybe; I have a suspicion this effect is pretty small.

download (2).png

 

Trends across patches

Finally I was curious how stable the game statistics were over patches. I collected historical data from champion.gg’s GitHub going back to patch 5.10, over a year ago. These are all ranked Platinum games.

Stats are pretty stable between patches. In general there’s not a lot of change in the game since 5.10. For instance, players averaged a 2.55 KDA in 5.10 and a 2.48 KDA now in 6.17. There is a general trend up in some of the cumulative stats like “goldEarned” or “totalDamageTaken”. That could easily be a symptom of games just taking longer over time; unfortunately I don’t have stats on game length to normalize with. Two highlights though. Experience has a big drop at the beginning of Season 6. I take this to be new accounts and/or people changing up how they play. Also totalHeal had a big bump up around patch 5.22. That could be the same general cumulative stat effect, but I think it may also indicate the addition of more healing abilities and the rise of healing supports like Soraka and Nami.

download (2).png

Champion diversity is pretty stable between patches. Up above I showed the distribution of playPercent across 5 roles for patch 6.17; here’s an animation of that distribution across patches. It’s pretty stable. So are the distributions for all the metrics I’m most interested in; goldEarned, KDA, winPercent, in general the distribution across champs looks the same between patches. I find that a bit surprising because I think of LoL game balance being pretty dynamic with a constantly changing meta. But it’s not really reflected in the stats.

 

LoL lag on Wifi

When I play LoL with a wired connection to my router in Grass Valley it looks like this. But when I play via WiFi it looks like this. Periodic ping spikes, from the usual 85ms to 170ms or so. Note the packet loss number is the same, about 10 packets/s. This ping pattern is not particularly noticeable while playing, but sometimes on WiFi I’ve had serious lag, disconnects, etc. Not so much when wired.

The WiFi link is as good as it could be. I’m 10 feet from the router, clear line of site, 30dB SNA. 802.11n, 5GHz, relatively quiet network. Either there’s something broken with the hardware or else WiFi really is just this unreliable. Need to experiment more. I sure wish I knew what algorithm LoL used to report ping. Last time I did the packet dissection work it looked like it was the RTT time on special ping/pong packets. Maybe they get lost and are retransmitted?

Cheating at League of Legends

A lot of people cheat while playing League of Legends. My impression is it’s not so bad that it ruins the game, but it sure is annoying.

Network invalidation

The simple and dumb cheats are denial of service attacks and drophacking. (See this discussion.) DoS attacks are directed against an enemy player in your game. Somehow you already know their IP address, and then you pay a couple of bucks to a bot farm to knock them offline. This happens a lot to high Elo players, particularly streamers. Poor Rivington (a Riot employee) basically couldn’t stream for a whole week because he’d be knocked offline every time he tried to play. Riot can’t stop DoS attacks directly, but they could definitely make it less appealing by having some sort of game invalidation if players are disconnected through most of the game. For some reason they’ve never wanted to implement that. DotA 2 has a good system.

Drophacking is a similar network denial attack, only in this case when you’re losing you crash the game server so it invalidates the whole game. This attack seems less common but not unknown and there’ve been a couple of severe instances at specific times, I assume once someone finds an exploit. Riot seems to be pretty quick about stopping drophacking, which is certainly expected given they control the server code.

Scripting

The other half of cheating is scripting, code running on the player’s computer to help them play better. I’ve seen a couple of what look like scripters to me in game. Specifically someone playing Sivir, where she’d cast her spell shield with inhuman swiftness to block my attempts to hook her as Thresh. I mean maybe she was just very good, but there was the time I cast the hook from inside a bush and she had at best 100ms to press E and yet there she is, pressing E. Or having a script press it for her.

Mostly this seems to be done via DLLs injected into the LoL process itself. The DLL allows Lua scripts to run, alter the UI, and perform player actions automatically. Two popular scripting tools are L# and Bot of Legends. Bot of Legends costs $10/month. Here’s a video of what it looks like to play with BoL.

There’s a huge variety of community-supplied scripts. See BoL Script Status for a gallery of scripts. Unfortunately most of the links go to paywalled forum posts. But scripts seem to be shared on GitHub. Here’s a couple of users I found: BoLFantastik, DraconisBoL.

Here’s an example code snippet that casts Ignite if it will guarantee a kill.

function AutoIgnite(enemy)
        iDmg = ((IREADY and getDmg("IGNITE", enemy, myHero)) or 0)
        if enemy.health <= iDmg and GetDistance(enemy) <= 600 and ignite ~= nil
                then
                        if IREADY then CastSpell(ignite, enemy) end
        end
end

Augmented intelligence

People who cheat at games baffle me, and make me angry when I play against them. But I do find the idea of augmented intelligence interesting, machine tools assisting people in doing things they intend. Like the Zed video I linked above has a short bit for “Jungle clear”, where you tell it “I want to kill this monster” and it combos your skills efficiently for max damage. The Insec video is another good example, scripting the ward / hop / kick combo that is a famously high skill play. Or not anymore, just press the button.

One challenge is UI for augmented intelligence, how do you present these higher level actions to the user? From the few videos I’ve seen there’s nothing impressive. That Insec video just shows a minimal line you draw, which way the enemy will go when you do it. Spare, but functional. Some of the other videos I’ve shown overload the player with information, drawing overlapping circles over everything. Maybe useful for debugging but not anything else.

The other question I have for scripting is how much it really helps the player. I have no doubt that spell-shielding Sivir was getting boosted by a tool that prevented me from hooking her. But there’s still a person in control of the character, it’s not a full bot, and she’s still having to make choices about where to go on the map and what to attack and when to go in or flee. I don’t think these scripts help with that. My gut feeling is the scripts probably cover about 40% of what a good player needs to do, the other 60% is up to them to do themselves. What’s funny is I’m in the bottom 25% of players. So if I see a scripter, they must be truly terrible if they have a 40% boost.

Ubiquiti: less LoL lag

One nice change from with the new network, less lag playing League of Legends.

With my old hacky setup with triple nat and routers acting as a bridge, I had a lag pattern like thishacky lag

Now with the Ubiquiti gear I have a lag pattern like this:

Lag after

Note the lack of spikes! I have no idea what those were, something was getting buffered or something weird before.

I don’t think median latency or packet loss really changed, but I’m glad not to see those ping spikes. Although TBH they didn’t affect my gameplay much.

LoL dotmap

Fresh off my heatmap attempt I made a second map of a single LoL game using a dot map. One dot per player recorded position (28,000 in all), colored by team.

Screen Shot 2015-08-17 at 6.04.56 PM

I think this treatment works better; the team color is really important information. But I miss the emphasis of dwell times that the heatmap accumulation algorithm gives. I’ve tried to fake it by using dots with 20% opacity but that’s pretty bogus. (Also easy to fudge, depending on dot size, opacity, and stroke weight you use.)

Still, an improvement, and I’ve also got a data extractor that’s creating more structured data so I can track individual players.

I did this in D3js because it was easy to. But I want to produce a static final output so there’s really no need for Javascript. I should look into data plotting tools in other languages. Maybe this is a time to try out some more of the big data Python tools, or see what Octave has up its sleeve. I think something like the heatmap algorithm is really what I want.

First light: League of Legends heatmaps

I took a crack at rendering the position data I found in the League of Legends live matc stream. Here’s a first take on TSM v TL game 1

Screen Shot 2015-08-17 at 3.59.13 PM

Interpretation

Not bad, it at least looks recognizable. The main trend is that there’s more activity on blue side (lower left) than red size (upper right). That matches what happened in game; TSM was red and they won, and dominated. The other basic pattern is you see the basic shape of the map and the paths through the jungle. This is expected.

But then it gets more subtle. I love the two blobs at upper left. I think these are times when TSM’s jungler was hiding in those bushes ready to gank for TSM’s top laner, will have to watch the game again to verify he really did spend a lot of time there. Als interesting to see the relative bias of activity over towards Baron instead of Dragon, I suspect that’s not a universal for all games.

Improvement

Lots to do to make this better. Some inspiration: this NYT treatment of similar data, which takes data from many games and uses dots instead of a heatmap. However my goal is more to highlight what’s interesting about a particular game, so have to apply their many-games approach carefully. And also these DotA maps which are basic but complete works.

#1 problem with my treatment is the single color scale: I really want red vs blue ramps for the two teams. But then I don’t want to mix them to purple! I suspect the heatmap treatment is really not the right tool here, I should consider dots like the NYT map. It’s about 26,000 dots in total per game. (600 per minute, games seldom go 60 minutes.) Also should look at hexbinning or whatever the cartohipsters are doing these days.

I’d also like to examine the time axis, see how the movement spreads over time. I don’t really want to make some interactive visualization though, a static image is better. I like what the NYT did breaking the game up into three phases.

Finally it’d be nice to be able to pick out individual players. Particularly the support and jungle since they roam more, but also bot and top to see what happened with lane swaps.

Implementation

The heatmap rendering is from heatmap.js. I like it for being a straightforward canvas implementation, and it is fast as promised. But the rendering is very limited, in particular I can’t come up with any way to render two categories of data in different colors in the same heatmap. (And the canvas is opaque, so I can’t just draw two superimposed, which would be awful for other reasons too.)

The data extraction is some dumb-ass Python to pull the position fields out of the stream data. Quick and dirty, need to clean it up if I do this for real. If a character doesn’t move I don’t draw their position twice right now. Also the stream data is remarkably messy, I need to do extra work to detect game start and end and filter out data from the previous game that sometimes got mixed in. And I should preserve per-player data to allow more flexible visualizations.

LoL live match stats

New feature on Riot’s pro game broadcast site: a live stats board. It updates once a second in your browser showing you game stats. Also features for Twitter messages, game stream info, etc. It’s the stats I’m interested in.

Stats scoreboard

Here’s the data on display:

  • Match type. Game #. Games won / lost by each team. Team and player names.
  • Kills in current game. Also objectives: inhibs, barons, dragons, towers.
  • Total team gold.
  • For each player: kills/death/assists, CS, and gold.

Data contents

The game stats are implemented with a web socket. (There’s also some JSONP being polled for other features; the stats are a web socket.) I wrote a Python program to record the data. They generally send one message a second, about 500 bytes, updates to things like player gold, kills, etc. It’s a pretty efficient implementation.

The data on the web socket is mostly what you’d expect to implement that display. Messages usually contain updates on player stats: total gold, current gold, experience points, and player position. Variables are only in the JSON blob if their value has changed. A bunch of oddball updates sometimes come through for things like CS, player kills, etc. And then teamStats updates for tower kills, etc. They’re also tracking player double kills, triple kills, etc. Nothing in the stream about item purchases that I’ve seen.

There’s also some special messages. The first message on the socket is about 14k and contains all the data that ordinary isn’t changing, stuff like player name. When a new game starts the info about what champions are in the game is sent along. When a game ends there’s a gameComplete message. That kind of thing.

The most interesting thing I’ve found in the data stream is player position. It’s currently not being used by Riot’s web client. Should be possible to use that to animate a version of the game. riftwalk.gg had something like that based on replays before it got shut off, would be nice to feed this stream to that visualization code.

Technical details

My Python client is having the socket closed on it every 90 seconds. I just re-open it for now, seems to work. The web client in Chrome doesn’t seem to be doing that. Wireshark tells me that there’s a ping/pong Chrome is exchanging every 45 seconds. I’m guessing the Python client isn’t responding to pong and after two failed pings the connection closes. A bit confused why the pong doesn’t come through, the Python library looks like it just handles that for me.

Update: I looked in Wireshark and found the Python client is sending pong responses, but they’re getting TCP fragmented into two packets maybe because of the way the async writing code works. I’ve opened an issue on GitHub seeing if my analysis is correct and whether it’s something that could change. Update 2: I guessed right! The author changed the code to not fragment the packet and now I can stay connected. Yay!

The web socket hosted at ws://livestats.proxy.lolesports.com/stats. The socket requires a JSON web token to connect, which is some signed blob, although it’s not tied to any personal secret like a password login. I pulled one out of my browser and decoded it via jwt.io, it contains a bunch of IDs. Also has what looks like an expiration date, token is good for a week. I just pulled the token out of my browser and reused it in the Python code.

Mac screen capture: creating League of Legends highlights

I felt like a huge nerd today and wanted to record a video highlight from a League of Legends. Lots of steps here to capture the game itself, capture video and audio on the Mac to a file, convert it to something usable, then upload it. Here’s all the steps.

Generate content: record game replay

The service replay.gg will record all your League of Legends games for you. It’s terrific! Using it you can watch one of your games later in the observer client. I use this to get the exact game scene I want to capture.

Capture content: video and audio capture

The Mac does not make it easy to capture full screen video and audio. I used to use the commercial product Screenflick to do this but it’s pretty buggy. So this time I did the capture with Open Broadcaster Software, which is a free. The UI is a bit more hackerware but for my purposes it’s perfect.

OBS records video pretty much right out of the box. I tinkered with the Advanced Output settings to record at the bitrate of 10,000 (overkill) using the faster preset. Note that OBS is doing h.264 encoding live while you go, so it’s taking CPU power. The “slow” preset definitely interfered with my game framerate. (Screenflick records with a very fast, disk intensive codec and then re-encodes later, which is kind of nice.)

Audio is a problem. Update: see this second post about sound. OBS recommends WavTap but I couldn’t make it work. Instead I installed SoundFlower, which also works well with OBS. Basically SoundFlower installs a kernel module that’s a new loopback audio device. You use the Sound control panel to tell the Mac to make SoundFlower 2ch the default audio device. SoundFlower then passes that through to your actual headphones or whatever, while also making the sound stream available to apps. Note that starting with Yosemite it’s getting very hard to run custom kernel drivers in MacOS. Thanks a lot, Apple.

Now I have OBS recording movie files to my hard drive of whatever is on my screen. Yay!

Edit content

The next challenge is editing the capture down to what you want to share. I’m allergic to iMovie, and AFAIK there is still no good free simple “let me cut 15 seconds out of my video” GUI tool for Macs. I ended up using ffmpeg to do this with these instructions. ffmpeg lets you pick to the nearest millisecond, but irritatingly VLC won’t show you milliseconds in playback, so precise cuts suck.

Here’s the command I used to cut from 00:02 to 00:19 of my recording and re-encode it at decent quality. Unfortunately you can’t just use “-copy” in ffmpeg because that doesn’t properly trim the audio for some reason; you have to reencode.

ffmpeg -i obs.flv -c:v libx264 -preset slow -crf 20 -ss 00:00:02 -to 00:00:19 out.mp4

Man I’d like a simple GUI program that lets me watch the movie and set a start time, an end time, and press a button to do this cut for me.

Share content

Now you have an ordinary MP4 movie file you can share anywhere. I uploaded it to Streamable, a lightweight hosting / sharing service for video that plays nicely with Reddit and friends. They re-encoded it to a 2260 kbps vp8+vorbis file which still looks pretty good. In particular I think they kept my 60 frame per second source, much appreciated.

LoL protocol: channels

I sliced my ~20 minute ARAM game packet capture a different way, looking at channel numbers. Enet is a multichannel protocol, it can contain up to 0xff different channels. No idea what guidance there is for using this feature, but here’s what I found. Note that my parser still breaks on some packets, so I discarded things that look malformed or very rare. Ie: report is not 100% complete.

Channel 0xff: control. 2%
Starts the game off with a CONN/VCON pair.
For the whole game, client sends PING roughly twice a second. It gets an ACK about 35-40ms later (my client’s RTT.) A new ping is sent almost exactly 500ms after the last ACK is received.
For the first three minutes, server sends PING roughly twice a second which then client immediately ACKs. Server pings mostly stop after 180 seconds, although I did see a single server PING at 519, 848, 964, 1666, and 1928 seconds.
The PING packets are generally just 12 bytes big, but occasionally are bigger: 30 or 31 bytes is next most common.

Channel 0x03: server to client. 42%
Entirely reliable packets. A whole lot. 54% are small (14 bytes is most common), but some get to 100s of bytes. I imagine this is the important game state.

Channel 0x01: client to server. 35%
This contains all of the traffic the client sends the server. A healthy mix of Enet packet types (reliable, unreliable, and unsequenced). 72% of these packets are very small (14, 24, or 25 bytes). Some are a little bigger.
I ran a second game which was a custom solo game for just 4 minutes with me doing nearly nothing, almost no input. There were almost no reliable packets sent by my client at all; that is consistent with the reliable packets being used for user input. I wonder if all the unsequenced/unreliable traffic is used for bot detection, tracking the user’s mouse position or other signals from the client?

Channel 0x04: server to client. 19%
A bunch of SUNR packets first; those are unreliable but sequenced. Then a stream of SUNS packets; those are unsequenced. No one packet length dominates, the most common is a 40 byte packet at 9%. But almost all the traffic is in the 40-60 byte length.

Channel 0x02: server to client. 1%
Entirely unreliable packets. Not many. 71% are 25 bytes.

Channel 0x05: server to client. 0.03%
This is a mystery. It’s very low traffic, 25 or so over the whole trace. But they’re there and they are sequenced.

Conclusions

I think channel 3 is most interesting as a source of lag; that’s the server sending reliable packets to the client. Channel 1 is also interesting since it contains the clients’ reliable packets to the server.

I just noticed that SUNS packets (unsequenced) still contain sequence numbers. That’s handy for monitoring out of order and loss even if the protocol doesn’t treat those as errors.

I also did a quick spot check of this data vs. a custom solo game I recorded for ~4 minutes where I did almost nothing. The traffic distribution was roughly similar other than the difference in  channel 1 I noted above.

Here’s a table of popularity of packet types and channel number.

    1469 .4164 PING   :ff
    1459 .4135   ACKK :ff
     299 .0848 ACKK   :ff
     298 .0845   PING :ff
       1 .0003 CONN   :ff
       1 .0003   VCON :ff

   38364 .2362 SUNS   :01
    8541 .0526 SREL   :01
    8540 .0526   ACKK :01
     967 .0060 SUNR   :01

   34606 .2131   SREL :03
   34217 .2107 ACKK   :03

   29401 .1810   SUNS :04
    1689 .0104   SUNR :04

    1510 .0093   SUNR :02

      23 .0001 ACKK   :05
      23 .0001   SREL :05

libenet / league of legends protocol success!

Last year I looked into the League of Legends real time protocol, the format of the UDP messages between the game server and clients. My recent lag problems motivated me to look again and I’ve gotten somewhere this time.

The protocol is said to be based on libenet 1.2 with some modifications. The body of the protocol itself is encrypted, presumably to make it harder for third party hacks to sniff data from the game. (It doesn’t make it impossible though, so once again DRM frustrates legit use without dissuading cheaters.) But I don’t care about the body, I just want the enet headers, the sequence numbers and retransmits and stuff. And that’s in the clear!

The best guide I’ve found is this Wireshark dissector, or rather an updated version Boreeas kindly gave me that isn’t checked in anywhere. The key thing is inside the UDP packet, the first 8 bytes are a not-very-interesting header. Then the 9th byte is an Enet command, the 10th byte is a channel number, and the 11th and 12th bytes are the sequence number. (To complicate things sometimes only the first 6 bytes are the header, so the command is the 7th byte, etc.) ACK packets have some bogus sequence number, but the first 2 bytes after that are the sequence number of the packet being acknowledged.

So I put all that together and wrote some Python Impacket code and now I have something printing a summary of UDP captures I made. Below is a few lines from my outputter. This shows the server sending a reliable packet on channel 3 numbered 01a9, then another numbered 01aa, then another number 01ac. My client acknowledges all three. But what happened to 01ab? The server sends that along 200ms later, either because it arrived out of order or else because the server knew to try to send it again. Note that in the meantime 01ad also went missing; that never showed up, so I’m confused. Still, it’s a start. I assume the LoL client shows lag if a reliable packet doesn’t arrive properly.

SREL   03 01a9 00167.521401   00000000: 0D 89 78 BC A7 80 96 CE  86 03 01 A9 00 38 D6 23  ..x..........8.#
  ACKK 03 01a9 00167.521538   00000000: F3 CC 6D 92 A7 03 01 03  00 00 01 A9 96 CE        ..m...........
  SUNS 01 0000 00167.542210   00000000: F3 CC 6D 92 A7 03 49 01  00 00 03 8C 00 0A 87 99  ..m...I.........
SREL   03 01aa 00167.562514   00000000: 0D 89 78 BC A7 80 96 E5  86 03 01 AA 00 07 6F 00  ..x...........o.
  ACKK 03 01aa 00167.562663   00000000: F3 CC 6D 92 A7 03 01 03  00 00 01 AA 96 E5        ..m...........
  SREL 01 0065 00167.583485   00000000: F3 CC 6D 92 A7 83 8E B4  86 01 00 65 00 1F 6B 4F  ..m........e..kO
SREL   03 01ac 00167.629336   00000000: 0D 89 78 BC A7 80 97 28  86 03 01 AC 00 18 D8 AB  ..x....(........
ACKK   01 0065 00167.629393   00000000: 0D 89 78 BC A7 00 01 01  01 AC 00 65 8E B4        ..x........e..
  ACKK 03 01ac 00167.629477   00000000: F3 CC 6D 92 A7 03 01 03  00 65 01 AC 97 28        ..m......e...(
SUNS   04 0000 00167.688278   00000000: 0D 89 78 BC A7 00 49 04  00 00 03 DD 00 3B BA D6  ..x...I......;..
SREL   03 01ae 00167.688330   00000000: 0D 89 78 BC A7 80 97 64  86 03 01 AE 00 10 F5 54  ..x....d.......T
  ACKK 03 01ae 00167.688425   00000000: F3 CC 6D 92 A7 03 01 03  00 65 01 AE 97 64        ..m......e...d
  SREL 01 0066 00167.709221   00000000: F3 CC 6D 92 A7 83 8F 31  86 01 00 66 00 1F 6B 4F  ..m....1...f..kO
SREL   03 01af 00167.736732   00000000: 0D 89 78 BC A7 80 97 A5  86 03 01 AF 00 44 2B 25  ..x..........D+%
  ACKK 03 01af 00167.736863   00000000: F3 CC 6D 92 A7 03 01 03  00 66 01 AF 97 A5        ..m......f....
ACKK   01 0066 00167.739947   00000000: 0D 89 78 BC A7 00 01 01  01 93 00 66 8F 31        ..x........f.1
  SUNS 01 0000 00167.740008   00000000: F3 CC 6D 92 A7 03 49 01  00 00 03 8F 00 0A 23 68  ..m...I.......#h
SREL   03 01ab 00167.765224   00000000: 0D 89 78 BC A7 80 97 C2  86 03 01 AB 00 1B BC 8D  ..x.............
  ACKK 03 01ab 00167.765389   00000000: F3 CC 6D 92 A7 03 01 03  00 00 01 AB 97 C2 01 03  ..m.............
SUNS   04 0000 00167.770715   00000000: 0D 89 78 BC A7 00 49 04  00 00 03 DF 00 23 31 79  ..x...I......#1y

Here’s a breakdown of packet types from an ARAM game I recorded. 23.77% of packets are from my client to the server, “send unsequenced”. Huh, what does my client have to say to the server that’s so volumnious and yet unimportant? About 41% of traffic is the server sending reliable packets and the client acknowledging them and another 11% is the client sending reliable packets and the server acknowledging them. 21% of the traffic is unsequenced packets from the server, or about the same number of packets as reliable ones. I’d expected more of a bias to unreliable packets from the server than that.

   20086 .2377   SUNS
   17498 .2070   ACKK
   17475 .2068 SREL
   15406 .1823 SUNS
    5670 .0671   SREL
    5101 .0604 ACKK
    1528 .0181 SUNR
    1311 .0155   PING
     203 .0024   SUNR
     197 .0023 PING
      40 .0005 SFRG
       1 .0000 VCON
       1 .0000   CONN

New LoL NA servers

Riot is finally moving the North American League of Legends game servers from the west coast to somewhere more central, Chicago,. Their network operations guy RiotAhab has been making a series of great posts about netops, his post about the move is good reading. Also buried in the discussion is a comment from dArtaganan, a Riot employee, giving us a new server IP: 104.160.131.1. (Compare old IPs like 192.64.170.78).

A simple ping from my house to the new IP is 70ms. Some random other Chicago IP was about 60ms. Theoretical best RTT (speed of light in copper) is 30ms. Riot is promising ping increases of “up to 30ms” for west coasters, which would put me at 65ms.

That IP is in AS6507. My route to them from my Kansas server (12ms away) ends at be2217.ccr41.ord03.atlas.cogentco.com, which could be a Cogent datacenter like this one. Or maybe Cogent just provides the link and the warehouse is owned by someone else. Note the old west coast IPs are also in that ASN, Riot didn’t set up a new one.

Riot’s ASN has 110 peers, which is impressive; compare 13 for my ISP or 6 for my server. Google has 200+, mega-backbone he.net has nearly 4000. Anyway, Riot’s peering efforts are clearly visible. I imagine each one of those 110 peers is a separately negotiated contract.

Diagnosing a weird LoL lag issue

I’m having a weird lag problem where I get massive packet loss playing LoL. But the reported ping stays low (35ms) and the game is mostly playable. Some small hiccups that look lag related, more than I’m used to, but it’s not hugely awful. Really don’t know what’s going on.

My logs are telling me I’m losing 2.4% of my packets. That seems awfully bad; 0.1% or so is more typical. Borderline surprised it’s playable, but who knows. It’s not clear why the LoL client still reports the 35ms ping; the usual client behavior is if you’re losing packets the reported ping goes up. Or at least it used to be, maybe that changed?

I’ve done every test I can think of to prove that it’s not my home network in general to blame. I can iperf3 burst UDP traffic all day reliably from my house to somebits.com in Kansas. That shares the same route over my ISP as far as cr1-9greatoaks-te-0-7-0-8.bb.spectrumnet.us; then the somebits packets go through he.net on their way to Kansas while the LoL packets go through spectrumnet up to Portland and Riot’s datacenter. That route looks fine, as well as I can test. (with mtr -u, a UDP traceroute).

Confusing things more, a friend of mine also plays on the same ISP in San Francisco. His client is not showing any lag like I am. But we share almost the same route, our routes converge on the fourth hop from 76-14-93-222.sf-cable.astound.net / 76-14-93-218.sf-cable.astound.net onward. So if there were a bad router it’d be close to my house. But then my link to somebits.com goes through that same route and I can test that thoroughly, and it’s showing no problem.

Frankly all signs point to something being wrong with my Mac, the client itself. Only I can reproduce the problem on a second machine, my laptop! Could it be my router? Possibly. But it’s worked fine in the past. I’ll try to test without the router soon.

Here’s some stats from a Wireshark capture I did in an ARAM I just played. I was Amumu.

LoL server address: 192.64.170.78

Wireshark statistics

  • 39750 packets from server, 44769 packets from client
  • 2003 packets reported lost by the client. 2.4% packet loss rate!
  • 39kbps from server, 17kbps from client
  • Average packet size 228 bytes
"Address","Port","Packets","Bytes","Packets A → B","Bytes A → B","Packets B → A","Bytes B → A","Latitude","Longitude"
"192.64.170.78",5107,84517,9616369,39748,6599894,44769,3016475,"-","-"
"192.168.0.20",53040,84517,9616369,44769,3016475,39748,6599894,"-","-"


==================================================================================================================================
Packet Lengths:
Topic / Item       Count         Average       Min val       Max val       Rate (ms)     Percent       Burst rate    Burst start  
----------------------------------------------------------------------------------------------------------------------------------
Packet Lengths     84519         227.56        54            1038          0.0627        100%          0.2400        73.682       
 0-19              0             -             -             -             0.0000        0.00%         -             -            
 20-39             0             -             -             -             0.0000        0.00%         -             -            
 40-79             46272         62.08         54            79            0.0343        54.75%        0.1600        2.285        
 80-159            26150         101.90        80            159           0.0194        30.94%        0.0900        838.818      
 160-319           7204          228.76        160           319           0.0053        8.52%         0.0500        351.673      
 320-639           4120          437.28        320           639           0.0031        4.87%         0.0600        73.648       
 640-1279          773           814.54        640           1038          0.0006        0.91%         0.0600        73.717       
 1280-2559         0             -             -             -             0.0000        0.00%         -             -            
 2560-5119         0             -             -             -             0.0000        0.00%         -             -            
 5120 and greater  0             -             -             -             0.0000        0.00%         -             -            

----------------------------------------------------------------------------------------------------------------------------------


$ sudo mtr -u 192.64.170.78
                                   My traceroute  [v0.85]
ub (0.0.0.0)                                                        Tue Aug  4 17:43:25 2015
Keys:  Help   Display mode   Restart statistics   Order of fields   quit
                                                    Packets               Pings
 Host                                             Loss%   Snt   Last   Avg  Best  Wrst StDev
 1. router.nelson.monkey.org                       0.0%   981    0.2   0.2   0.2   0.7   0.0
 2. 76-14-35-1.sf-cable.astound.net                0.0%   981    9.8  11.8   4.0 156.4   9.6
 3. 104.220.254.17                                 0.0%   981    7.4   9.2   3.6  31.3   4.0
 4. 76-14-93-218.sf-cable.astound.net              0.0%   981   14.6  17.2   7.7 234.4  22.8
    76-14-93-222.sf-cable.astound.net
 5. cr1-wsache-a-be-100.bb.spectrumnet.us          0.0%   981   11.8  14.2   9.1  37.2   3.8
 6. cr1-55SMarket-te-0-0-0-8.bb.spectrumnet.us     0.0%   981   11.1  14.7  10.3  37.6   4.7
    cr1-55SMarket-te-0-0-0-10.bb.spectrumnet.us
    cr1-55SMarket-te-0-0-0-9.bb.spectrumnet.us
    cr1-55SMarket-te-0-0-0-19.bb.spectrumnet.us
    cr1-55SMarket-te-0-0-0-11.bb.spectrumnet.us
 7. cr1-9greatoaks-te-0-7-0-6.bb.spectrumnet.us    0.0%   981   11.5  14.2   8.2  36.4   3.7
    cr1-9greatoaks-te-0-7-0-8.bb.spectrumnet.us
    cr1-9greatoaks-te-0-7-0-9.bb.spectrumnet.us
    cr1-9greatoaks-te-0-7-0-7.bb.spectrumnet.us
 8. cr1-pdx-te-0-0-0-4.bb.spectrumnet.us           0.1%   981   44.3  30.8  23.8  56.2   4.5
    cr1-pdx-te-0-0-0-5.bb.spectrumnet.us
    cr1-pdx-te-0-0-0-6.bb.spectrumnet.us
 9. cr2-fdcp-t4-4.bb.spectrumnet.us                0.0%   981   29.4  34.2  25.2 376.9  25.7
10. 216.243.25.86                                  0.0%   981   28.3  29.9  24.8  51.3   4.0
11. ???

Graph of packets / second

Packets per second

Update

Some updates after a few experiments

  • Problem definitely occurs on two different computers, an iMac and a Macbook Air
  • Problem occurs without my router / switch. Still plugged into my cable modem.
  • I played a game with a friend of mine who happens to also be in San Francisco on the same ISP and plays on a Mac. He had no lag, I did. Here’s my Logs of Lag report and here’s his. I lost 80 packets a minute, he lost 2. WTF? According to traceroute our routes are the same after the 4th hop above, so if it’s a problem in the route it’s something very close to my house at my ISP.
  • However, I can happily shove a huge amount of UDP traffic into my house with no problems. And those packets also traverse that same route to hop 4.
  • I see the same problem on a Windows box in my house. (35 packets lost / minute in a Custom game, which is line with results on the Macs I play on.)

My next step is to try playing through a VPN and see if it helps. I’d also like to understand better what it means for the LoL client to know it’s lost 2.4% of packets and yet still report a low ping. That seems odd; usually the reported ping number goes up in response to retransmits, or at least I thought it did.

Update 2

A friend of mine has a VPS at directspace.net, which is either in the same datacenter as Riot NA or else very nearby. He ran an  iperf2 server for me. Here’s some redacted data testing from my problem network.

iperf shows 69 packets out of 26224 lost, and 47 out of order. that’s about normal for a working link I think, and 1/10th the loss rate I’m seeing from the game.

mtr shows at worst 1 packet dropped out of 100. the stddev to hop 4 is higher than I’d like though.

$ iperf -l 300 -u -t 60 -i 10 -c XXX.XXX.XXX.XXX
------------------------------------------------------------
Client connecting to XXX.XXX.XXX.XXX, UDP port 5001
Sending 300 byte datagrams
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.65 port 34071 connected with XXX.XXX.XXX.XXX port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] 10.0-20.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] 20.0-30.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] 30.0-40.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] 40.0-50.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] 50.0-60.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3]  0.0-60.0 sec  7.50 MBytes  1.05 Mbits/sec
[  3] Sent 26225 datagrams
[  3] Server Report:
[  3]  0.0-60.0 sec  7.48 MBytes  1.05 Mbits/sec   1.561 ms   69/26224 (0.26%)
[  3]  0.0-60.0 sec  47 datagrams received out-of-order

$ mtr --report -c 100 -u XXX.XXX.XXX.XXX
Start: Wed Aug  5 21:37:40 2015
HOST: ub                          Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- router                     0.0%   100    0.2   0.2   0.2   0.5   0.0
  2.|-- 76-14-35-1.sf-cable.astou  1.0%   100    9.3  11.0   5.4  57.1   7.2
  3.|-- 104.220.254.17             0.0%   100    9.9   9.4   5.0  28.1   4.1
  4.|-- 76-14-93-222.sf-cable.ast  0.0%   100   14.5  15.0   9.9 114.6  11.0
  5.|-- cr1-wsache-a-be-100.bb.sp  0.0%   100   11.9  14.9  10.2  33.2   3.7
  6.|-- cr1-55SMarket-te-0-0-0-8.  0.0%   100   11.9  13.4  10.4  32.0   2.3
  7.|-- cr1-9greatoaks-te-0-7-0-8  0.0%   100   14.6  15.1  10.3  33.1   4.6
  8.|-- cr1-pdx-te-0-0-0-4.bb.spe  0.0%   100   26.6  29.8  26.2  47.5   3.9
  9.|-- cr2-pdx-te-0-1-0-4.bb.spe  0.0%   100   29.7  29.6  26.1  47.8   3.3
 10.|-- directspace.nwax.net       1.0%   100   29.9  31.8  26.0 166.0  15.4
 11.|-- 69-163-34-113.in-addr.arp  0.0%   100   28.1  28.8  25.2  31.4   1.2
 12.|-- XXX.XXX.XXX.XXX            0.0%   100   28.6  29.3  26.1  47.0   2.7

Update 3: I have a theory: out of order packets. My mtr tests are telling me there’s something a bit flaky between hops 3 to 4. Occasionally a packet will take a very long time, like 200ms, and the stddev on that hop is way higher than the others. I wonder if an out of order packet causes the LoL client to drop it or otherwise treat it as a lost packet? To further complicate things, mtr -u shows me that there are many different paths on my route. All the same lengths, but node 4 (the suspect one) has a couple of different IP addresses that show up. If only one path is congested that will cause a lot of out of order packets.

I don’t know what LoL does with out of order packets. ENet, the protocol LoL is based on, is pretty clear about what it does:

ENet provides sequencing for all packets by assigning to each sent packet a sequence number that is incremented as packets are sent. ENet guarantees that no packet with a higher sequence number will be delivered before a packet with a lower sequence number, thus ensuring packets are delivered exactly in the order they are sent.

For unreliable packets, ENet will simply discard the lower sequence number packet if a packet with a higher sequence number has already been delivered. This allows the packets to be dispatched immediately as they arrive, and reduce latency of unreliable packets to an absolute minimum. For reliable packets, if a higher sequence number packet arrives, but the preceding packets in the sequence have not yet arrived, ENet will stall delivery of the higher sequence number packets until its predecessors have arrived.

But I don’t know how LoL uses these features, in particular what packets are marked reliable / unreliable.

The good thing about this theory is it explains a lot of the facts I see, including why my friend at the same ISP doesn’t have the same lag. (He’s beyond hop 4!). The bad thing about this theory is I still can’t really reproduce the presumed failure with iperf. iperf3 does report out of order packets (as an error message!) but I’ve only been able to induce it to do that with ridiculously high bandwidth tests, and even then not reliably. But maybe iperf3 is really polite and sends packets spaced exactly N ms apart so is less likely to have an ordering problem?

Here’s an ICMP traceroute showing the high stddev at node 4.

$ mtr -n somebits.com

                             My traceroute  [v0.85]
ub (0.0.0.0)                                           Wed Aug  5 23:03:04 2015
Keys:  Help   Display mode   Restart statistics   Order of fields   quit
                                       Packets               Pings
 Host                                Loss%   Snt   Last   Avg  Best  Wrst StDev
 1. 192.168.0.1                       0.0%   539    0.3   0.3   0.2  29.1   1.2
 2. 76.14.35.1                        0.4%   539    8.0  11.0   4.7  60.6   7.7
 3. 104.220.254.17                    0.0%   539    8.0   9.6   5.5  30.4   4.7
 4. 76.14.93.222                      0.6%   539   13.5  17.0   9.7 229.9  22.1
 5. 208.76.187.33                     0.0%   539   28.9  14.1  10.2  36.7   4.1
 6. 208.76.185.26                     0.0%   538   12.8  14.6   9.0  35.5   4.8
 7. 208.76.185.58                     0.0%   538   13.6  14.0  10.0  36.8   3.7
 8. 206.223.116.37                    0.0%   538   14.7  16.5   8.5  44.6   5.6
 9. 184.105.213.106                   0.0%   538   38.3  44.2  37.0  74.5   5.9
10. 184.105.222.22                    0.2%   538   91.2  82.6  62.7 121.7  14.5
11. 184.105.213.37                    0.0%   538   71.1  69.6  62.9  96.7   5.8
12. 216.66.78.90                      0.2%   538   56.5  56.6  48.1  83.5   6.2
13. 69.30.209.138                     0.0%   538   49.6  54.4  47.9  83.6   6.1
14. 192.187.107.5                     0.0%   538   53.4  54.9  48.2  87.9   5.4
15. 107.150.51.74                     0.0%   538   51.3  52.1  47.4  96.1   4.8

Update 4: A VPN fixes my problem! I sort of predicted it would, glad to confirm my hunch and also nice to have a workaround until the real problem is fixed. I set up a TCP VPN through Cloak, promised to US West Coast. I ended up going through Seattle. The resulting log shows a little more latency than without the VPN but also nearly no packet loss. Yay!

I set up Cloak because they have a really great Mac client, easy to get going. If I make a habit of this I may consider a VPN endpoint I own up in Seattle / Portland. Would rather just fix my ISP problem though. Don’t want to be paying $10 a month just to fix someone else’s broken service.

Update 5: this problem went away, and I don’t know why. I’m now playing games with 0.2 packets / s, very good, and no obvious lag. It may have been fixed by the Riot server move to Chicago, that’s the most likely explanation. But I’m still struck by the way I was getting this lag and my friend playing the same game with me on the same ISP wasn’t! That fourth hop from me is still showing suspiciously high standard deviation, so whatever that means it may well be unrelated.

LoL API: match data

A long hard look at what is in Riot’s /match API call. It is well documented but those docs are about the individual trees, this is the forest level view. Particular focus on data that’s not visible in the match history view. (This is NA match #1892290414. None of the participants are my friends, but it is ranked and therefore public.)

Long story short, the most interesting data that’s not currently visualized in the match history pages includes:

  • player positions every minute
  • totalTimeCrowdControlDealt
  • 10 minute averages for player performance: CS, gold, etc
  • 1 minute reports on player XP, CS, etc. (gold is currently visualized)

Top level match object:
Metadata about the game. Game type, map, server version, etc.

Teams
some top level stats on team aggregate performance. Very little data, but does have bans.

participantIdentities
summoner id, name, link to match history. This object exists but contains no data for non-ranked games. (No matter whether my API token account is friends with the player or not.)

Participants
Champion, Summoner spells, Masteries, Runes
Explicitly not any identity info other than “highest achieved season tier”.

> Stats
Detailed per-player info on whole match. level, KDA, items, etc
Unvisualized stuff:
double kills, penta kills, unrealKills, killing spree
various “scores”, all set to 0
first tower, first inhib
totalTimeCrowdControlDealt

> Timeline
None of this data is visualized by Match History.
Contains Role and Lane
Also contains average stats every 10 minutes for creeps, xp, gold, csDiff, xpDiff, damageTaken, damageTakenDiff

Timeline
Timestamped frames every 60 seconds

> participant frames
unvisualized: player position, level, XP, CS.
visualized: player gold

> events
timestamped events like item purchases, skill ups, wards placed, etc. some events like champion kills contain positions. (sadly, not wards.)

Riot’s League of Legends API and match privacy

I’ve been dorking around with the Riot API, for League of Legends. They’ve done a remarkably good job on it, particularly for a game company. The API product, the docs and developer registration and stuff, is well executed. (I say this as someone with some personal expertise.) And they are providing a huge amount of data, particularly detailed info on specific matches.

Here’s an example visualization of a match, from Riot’s own web product. All the data behind that match history view is also available in JSON form.

Anyway, one specific question is how to find matches. There’s two methods for looking up matches. The old /game API returns all matches for a given summoner ID (ie, a player). And the newer /matchhistory API returns all matches for a given summoner ID, but only ranked matches. Riot has said repeatedly that they think of ranked matches as public data and will always make that info available to anyone. But that other matches are casual and should be private. OTOH they haven’t implemented that yet, at least not entirely. Here’s the state of things today AFAICT

  1. Ranked game data is entirely public, including summoner identity
  2. Other game data is entirely public too, but does not include summoner identity except...
  3. You can see summoner identity for all games played by friends of yours and...
  4. Your Riot API developer token acts as you, and thus you can see identities of friends.

These principles apply to both the /game and /matchhistory APIs for “find me games from this person”. But they also apply to the very detailed match data returned by /match. They will return a lot of detailed data for any game, even a custom ARAM (as casual as it gets). However if you’re not friends with a player it won’t show you their summoner details. Ie: the game is anonymous.

At least, I think that’s how it works. I should confirm more.

They keep saying they’re going to disable the old /game API. That will make it more difficult to find match IDs for non-ranked games. OTOH they’ve been saying they’re going to do that for a year now and haven’t.

Update: the bit about seeing data for friends may only be true for the old /game API. It seems not to be true for specific match data returned by /match.

League of Legends bandwidth usage increasing

I pulled some new stats out of Logs of Lag, the average bandwidth used by the game client. Each point is the average for all logs I have for the week. It shows that the client has roughly doubled its bandwidth usage over the past three years.

LoL bandwidth usage

The absolute usage is still very small; well under 50kbps, or the speed of good ol’ dialup. (Burst usage is significantly higher though, maybe 4x.) Mostly I find the trend interesting. Also surprised not to see a clear step function as patches are released, although maybe that pattern is hiding in the data.

As with my previous analysis the huge caveat with these reports is that I don’t have an unbiased sample of LoL players. I only have logs  uploaded to me by Logs of Lag users, which are undoubtedly biased towards people with network troubles. I think that bias won’t skew this bandwidth usage number much though, it has much more impact on any inferences I can draw about player ping times, packet loss, etc.

Speaking of those skewed data, here’s an update from last fall’s summary with significantly more sample logs now.

matchLength = 1736.0  (29 minutes)
bestPing = 80ms
medianPing = 90ms
averagePing = 103ms
stdDevPing = 53ms
bytespsIn = 4706 bytes/s
bytespsOut = 666. bytes/s
lostPerMin = 11.5 packets/minute

More Logs of Lag aggregate stats

Following on my analysis of the average LoL game, here’s some scatterplots and histograms of various statistics for games. Specifically, for each game I’m looking at match length (0-3600 seconds is typical), best ping (10-150ms is typical), median ping (10-150ms is typical), and packets lost / minute (0-1 is typical, but long tail).

A huge caveat for this data: this is not a valid statistical sample of all LoL players. This is a random sample of Logs of Lags users, almost certainly biased towards people with network problems. I don’t intend to publish this data widely because it’s not a fair sample.

Honestly, the scatter plot is not the best treatment here; too many dots, not enough correlation. The histograms at top and right examining single variables are probably more interesting. Some notes:

  • Median ping and best ping are pretty tightly correlated. No big surprise there; they are nearly identical on a connection with low jitter and no packet loss. Not sure about the diagonal lines above the x=y line, maybe an artifact of how the game synthesizes a fake ping number in the presence of packet loss?
  • People’s pings are an interesting bimodal distribution, roughly peaking at 50ms and 110ms. I can’t account for the relative unpopularity of 80ms. Well if this were all North American data I’d say it was west coast vs. east coast, but I get a fair amount of European uploads too.
  • Packet loss / minute has a lovely long tail distribution. FWIW, I call anything over 5 a “bad link”; that’s ~30% of my logs, perhaps I should move that number up.
  • I was hoping to see evidence of correlation between packet loss and best ping, on the theory longer connections would be worse. I don’t see any evidence of that in the picture, it’s just a mess of dots. Need a better analysis tool. Same problem with packet loss vs. match length
  • Similarly, I can’t draw any conclusion from median ping vs. match length. That previous graph I did suggests the average ping for players does not go up during the game.

Bandwidth usage of LoL games over time

I had a theory that packet loss often gets worse after about 20 minutes of a League of Legends game, because people tend to group up and there’s more team fights. As a quickie-test of that theory, here’s a graph of the average characteristics of thousands of LoL netlogs for games that last 30-60 minutes.

Screen Shot 2014-11-19 at 4.32.19 PM

Not a lot of trend here. Bandwidth (grey line) does go up over time, but not radically. That could be just as much because cooldowns tend to go down as folks gear up as any effect of people grouping up. No useful visible trend in ping or lost packets, but that may be because the analysis is not good enough.

Lots of errors in this. The regular drops every minute are probably an aliasing problem having to do with the way the logs sample every 10 seconds.. usually. The population of netlogs is a mix of various game types, although by limiting it to 30+ minute games it’s mostly the main Summoners Rift games. (ARAM would significantly distort my hypothesis.)

Averages are a terrible way to calculate aggregate stats about packet loss and ping. But I don’t think they’d hide a trend of average ping or packet loss going up as a game progresses, I’d expect to still see it. Maybe not with the packet loss; the aggregate loss is so low perhaps it’s just not visible.

Logs of Lag summary stats

My Logs of Lag tool now has collected some 25,000+ logfiles. It’s a heavily biased sample: people mostly bring logs to my site if they have network trouble, but some stats nonetheless. Numbers are the average of each stat, with SD in parentheses

  • Best ping: 85ms (153)
  • Median ping: 97ms (389)
  • Packets lost / minute: 8 (120)
  • Game length: 28 minutes (13 minutes)

Would be nice to publish something from this data. I sure wish I had a way to get a representative sample. I wonder if I can convince some group of players to just upload their logs, whether they have problems or no. Would still be biased but maybe useful.

Here’s the kludgey script I use to generate a CSV file of all the results, which I can then feed to my 20 year old C program that calculates averages and standard deviations. Very quick and dirty, I should tackle a project of handling user data as more than flat JSON files.

for f in *; do
  ~/lol-netlog/logToJson.js < $f | 
  jq '"\(.matchLength),\(.packetsLost),\(.packetsLost/.matchLength),\(.medianPing),\(.bestPing)"'
; done > /tmp/logs.csv

League of Legends game protocol

I continue to be interested in understanding League of Legends lag. It’s a custom UDP protocol, so the usual way of measuring TCP packet loss doesn’t work.

I realized today the game must have something like a sequence number in the protocol. Apparently the LoL protocol is based on ENet, an open source “reliable UDP library”. There’s no dissector for ENet included in Wireshark but Google searches suggest several people have written them. packet-lol also has a LoL dissector but it is a couple years old, no idea if it’s still valid.

I’ve been hanging out on Freednode ##loldev recently, a nice little IRC channel. One thing they’re working on is documenting the observer protocol on a GitHub Wiki. But apparently that’s a totally different protocol from the UDP live game, based on HTTP requests for 30 second chunks of the game as well as keyframes, etc. A fair number of third party tools use the spectator protocol, sites like riftwalk.gg are doing some great game analysis. Neat stuff, but not relevant to the lag experienced while playing the game.

Here’s a big stack of links I’ve collected relevant to LoL protocols.

Some quick ad campaign stats

I ran some simple ads to promote Logs of Lag, my League of Legends netlog parser. I’m having a hard time getting attention and thought it’d help to get a bit of paid traffic. I invested, oh, $20 in all of this, trying to bottom feed some traffic. Results after a week or two of trying:

Google Adwords

0.18% CTR. 4468 impressions, 8 clicks, $2.73

Screen Shot 2014-06-26 at 2.03.14 PM

Very bad results, particularly on the search ads. Google’s minimum bid for a relevant keyword like [league of legends lag] seems to be at least $1, and apparently Google is happier showing no ads than showing cheap ads. 4339 of the impressions were via the Display Network. Near as I can tell AdWords gives me no way to see where those ads actually displayed. Bummer.

Bing Ads

0.59% CTR. 848 impressions, 5 clicks, $0.17

Straight-up clone of the Google ad campaign. But Bing Ads is quite happy to show ads for $0.10 CPC, so the good keywords I wanted got some impressions and clicks. No display ads at all; not sure if I wasn’t eligible or there was just no inventory.

Twitter Ads

Too early to tell. But my ad is a poor match for Twitter. All you can promote is a tweet, and I didn’t want to write a special ad tweet for my website. Also hard for me to imagine a Twitter user will be inspired to try my tool by a Twitter ad, particularly on a mobile device. I think Twitter Ads may be better suited for brand campaigns.

Reddit Ads

0.94% CTR, 14030 impressions, 132 clicks, $10.

Screen Shot 2014-06-26 at 2.11.33 PM

 

By far the most successful of my ads. In part because I could target it so specifically to /r/leagueoflegends, a big community. Also Reddit ads are cheap. It’s a pretty interesting ad product really, particularly the way ads become stories that get Reddit votes, comments, etc. I’m surprised it’s not better known. Reddit has a blanket $0.75 CPM rate which seems fairly cheap to me, particularly given the value of Reddit’s audience. The ad tool sure is primitive though. I’m left wondering why Reddit doesn’t pursue an ads business more aggressively.

Conclusion

Small ad campaigns are cheap. OTOH I didn’t set up any way to measure actual conversion. What I want is to get my tool in people’s minds so they remember to try it a month from now, and I’m not about to do the necessary work for such a small side project of mine. I don’t regret the $12.90 I spent though. I’d definitely go back to Reddit ads to get attention for something there, particularly if the organic way of getting Reddit attention doesn’t work out.

 

Logs of Lag ready to go

My Logs of Lag site is ready to launch. It works well, a clean and simple way to drop a League of Legends logfile onto a web page and see some statistics.

Not sure how to properly “launch” this yet. Success would be some visibility on the League of Legends Reddit, I’ll probably post it on Monday but it’s a crapshoot of the first 15 minutes whether it gets upvotes or not. I don’t expect an amazing response, this kind of tool is really something more useful to hang around and be available for months or years when people need it.

I’m pretty happy with how the final project came together. I was worried for a long time about the visual style. I still don’t think it’s great, but adding a basic background image texture and switching the fonts from Helvetica/Arial made a big difference in making it feel “real”. And I don’t want to do the over-produced glitzy graphics thing that’s popular with most gaming sites, I find that a useless distraction.

Ideas for future features:

  • Highlight “bad” data. Ie; if the loss/second is greater than some threshold, make that show up in big angry red warning font. I want to collect some logfiles from users to see what is typical before building a classifier.
  • Parse broken logs. In particular the logfile gets wonky if the game disconnects, would be nice to parse that correctly.
  • An analyzer for a whole directory of files. This is the way lolparse.com works, presenting summary statistics for gameplay in many games. It’d be useful to characterize lag for many games as well. Totally feasible given all the work is client-side, it could be fast. A histogram showing the distribution of median ping and median packets/s loss would be a good start.

And ideas for the server:

  • Replace the Python CGI with a real server. I have a Node version but I’m not sure I like Node. Porting the CGI to Gunicorn would suffice for scaling.
  • Or.. Remove the server entirely. Just make the client Javascript upload stuff to S3.
  • Or.. commit to a real server, and add logins and user data management.

League of Legends packet loss

I play LoL half the time on a wired DSL line in San Francisco and it plays just fine. The other half the time I play on a fixed wireless network link in rural California and I get enough lag it’s not much fun to play. I’m trying to figure out if the source of that lag is my ISP’s wireless network or something else.

LoL has net logs which are remarkably helpful. The LoL client reports it’s losing about 300 packets in a 30 minute game, typically 1 or 2 every 10 seconds. And occasionally one bad lag burst, 20 lost packets in a 10 second frame. That’s consistent with what I see in the game, the occasional lag hiccup and then once or twice a game really bad lag. I’ve also poked around a fair amount into the UDP packet stream for the game to measure bandwidth, burst speeds, etc. It’s hard to diagnose without anything like TCP sequence numbers. But FWIW the game never seems to get much faster than 40,000 kbits/sec or so, well below my ISP’s honest speed of 1 mbit/sec.

I was guessing the link layer of the fixed wireless link is causing the packet loss. But my ISP has been great in helping me figure this out. They tell me they measure link packet loss and there isn’t any. Also the network equipment does have various retransmits etc to work around wireless flakiness. Another possibility is my router, or maybe even something in the Internet outside my ISP. Hard to know!

Along the way I’m trying to learn more about ARP caches. This documentation of the Linux ARP cache is helpful. So is the command “ip -s neighbor list” for inspecting the state of the ARP cache, although I don’t fully understand the output.

 

Live streaming LoL with low bandwidth

Trying to watch League of Legends live broadcasts (Youtube) in Grass Valley on my slow fixed wireless link. My link is throttled at 768kbps, with a burst up front up to 2500kbps for a short time (15 seconds?). In San Francisco with the faster DSL I can watch 720p no problem and generally think Twitch is the most reliable. How about on a slow link? Conclusion: YouTube 360p Azubu 360p.

All tests are using Google Chrome on a Mac. Bandwidth is me eyeballing the median off of Tomato’s realtime bandwidth graphs. Numbers may be limited by my ISP’s 768kbps hard cap, I’m not entirely sure when the throttle applies. Measurements were taken during the game when the whole screen is live with scrolling backgrounds; bandwidth is lower if most of the screen is static.

  • 340kbps   youtube 240 live   fmt=92
  • 450kbps   twitch low (240?)
  • 530kbps   azubu 360p
  • 800kbps     youtube 360 live   fmt=93
  • 900kbps     twitch medium (360?)
  • 1100kbps? azubu 480p

All but the last option are reasonably reliable for at least a few minutes watching. Quality is not great. The lower 240p category is hard to watch, 360p isn’t bad. Audio is mostly fine (except Twitch low.) My impression is YouTube quality is better in both speed categories. It also seems to handle stream glitches a bit better. I think Azubu is stretching the truth in their reported resolution. (Update: it’s 360p, just more loss on the compression.)

I wish I knew which codecs everyone was using. No easy way to get that info from the Flash players, although presumably it’s determinable on inspection. YouTube’s debug info has those fmt= codes but there are no entries for that on the Wikipedia page for YouTube formats. This YouTube help page on how to broadcast suggests they’re using H.264 for video and AAC for audio. (The bandwidths line up with my observation, too.) A bit surprised they’re not using WebM/VP8, but maybe it’s a hardware support thing.

The video content is a bit rough for codecs, btw. Rendered graphics. And the whole screen is constantly scrolling, not many static parts of the screen. Even the background alters on scrolling because of the perspective projection the game uses.

lolss

My ISP’s burst interacts strangely with the streaming services. My thinking is that my 768kbps sustained network is just not quite fast enough for Youtube 360 or Twitch Medium, but my ISP doesn’t actually enforce that throttle for 15-30 minutes. Maybe because I’m only a tiny bit above my limit? Dunno.

Also worth noting that only Youtube has the weird sawtooth bandwidth thing. Azubu and Twitch both deliver a more consistent stream. I’m not sure if this really matters, given buffering in the network. I’m willing to bet Youtube is doing what they do on purpose, but I don’t understand why. The “stats for nerds” in YouTube’s player hangs at 0kbps, then bursts up to 1400kbps about 1.5s every 5s or so.

Graph below: YouTube 240p is the jagged line. The smooth line is either Twitch or Azubu, forget which.

Screen Shot 2013-08-31 at 1.29.14 PM Update: after watching a couple of hours I’m using the Azubu 360p stream. The YouTube 360p stream is better quality, but it’s just a tiny bit too much bandwidth for my link; the stream pauses every minute or so, very annoying. Azubu has the stream that’s just right for my bandwidth. They’re a bit odd in they’re serving a 530kbps 360p stream instead of 800kbps. The compression artifacts are awfully visible. But it’s better than the 240p options.

I think Azubu is using the same codec as everyone else. OTOH my Macbook Air’s fan is running pretty hard now, the Flash player seems to be using double the CPU of YouTube’s when viewing full screen. Not a big deal, but something’s different.