Example of a huge roboport network area showcasing the complexity addressed by the rectangle union optimization
Example of a huge roboport network area showcasing the complexity addressed by the rectangle union optimization

Factorio Dedicated Server Enhancements in Version 2.0: Stability and Performance Improvements

Factorio version 2.0 is bringing significant enhancements not just to the core gameplay, but also to the backbone of multiplayer experiences: the dedicated server. While much of the development focus has been on exciting new features and quality of life improvements, the team has also been diligently working on crucial technical optimizations and bug fixes that directly benefit Factorio Dedicated Servers. This article dives into some of the key improvements that will make your dedicated server experience smoother, more stable, and more performant in the upcoming 2.0 release.

Addressing Deterministic Multithreading Challenges for Server Stability

One of the more intricate issues tackled in the 2.0 development cycle revolved around deterministic multithreading. A particularly challenging desync bug was reported, highlighting discrepancies between different machines in a multiplayer environment. Initially, the suspicion fell on mods, but thorough investigation revealed a deeper, underlying problem within Factorio’s core threading logic.

Reproducing the desync proved difficult initially, but the breakthrough came when it was isolated to systems with differing numbers of CPU cores. This pointed towards a subtle determinism issue in how Factorio handled chunk generation across multiple threads. Specifically, a combination of factors was needed to trigger the bug:

  1. A mod actively listening to chunk generation events and modifying tiles.
  2. A mod requesting the generation of multiple chunks simultaneously.
  3. A mod forcing immediate chunk generation.
  4. Running the game on servers with varying CPU core counts.

The logic designed to expedite chunk generation by utilizing available CPU cores inadvertently introduced slight variations in results based on the core count. This seemingly minor difference could lead to desyncs in specific modded scenarios. The fix implemented for 2.0 addresses this core threading determinism issue, which has been present in the game’s code for a considerable time. While the solution itself was not overly complex, diagnosing and pinpointing the root cause required significant effort and expertise, showcasing the complexities of deterministic multithreading in game server environments.

Enhanced Multiplayer Auto-Pause for Dedicated Server Management

Factorio dedicated servers feature a convenient auto-pause functionality: when the last player disconnects, the server automatically pauses the game. This is invaluable for preventing unwanted base progression or biter attacks when no one is actively playing. However, two key edge cases have been addressed in 2.0 to refine this feature and enhance server management.

Firstly, previously, a server would instantly resume as soon as a player attempted to join, even before the joining player had fully loaded into the game. This immediate unpausing was an oversight. In 2.0, dedicated servers will now remain paused until at least one player has fully loaded into the game, ensuring a smoother and more controlled server resume process.

Secondly, the process of joining players catching up to a running game, while generally effective, could become problematic on very large maps or with slower internet connections. A joining player might require several minutes to download, load, and synchronize with the server, while the game continued running for existing players. To address this, version 2.0 introduces a new dedicated server option: “auto-pause when a player is joining.” This feature does exactly as it describes, pausing the server when a new player connects, ensuring everyone can start playing together without feeling rushed or left behind during the loading process. This new option provides server administrators with finer control over the multiplayer experience, especially in scenarios with larger maps or communities with varying connection speeds.

Faster Construction Robot Task Processing for Improved Server Performance

Construction robots are a cornerstone of efficient factory building in Factorio. However, in scenarios with massive bases and extensive roboport networks, a performance bottleneck related to construction robot task assignment has been identified and significantly improved for 2.0. The issue manifested as players frequently encountering alerts like “600 jobs missing materials/robots,” indicating delays in robot task processing.

The core challenge lies in efficiently determining if a construction robot from a logistic network is in range to perform a given task. The original range check had a complexity of O(Roboport-Count), meaning the processing time scaled linearly with the number of roboports in the network. In player-built megabases with tens of thousands of roboports, this check could become computationally expensive, potentially impacting server performance. To mitigate this, the game limited the number of construction robot tasks processed per tick, leading to the “600 jobs missing” alert phenomenon.

While increasing the number of tasks checked per tick was not a viable solution due to the potential performance impact with large roboport networks, a more fundamental algorithmic optimization was needed. The breakthrough came from leveraging existing game logic used for rendering roboport coverage areas. This logic efficiently computes the union of roboport logistic and construction zones, resulting in a set of deduplicated rectangles representing the total coverage area.

By combining this rectangle union calculation with sorting, the developers were able to implement a binary search approach to check if a task falls within a roboport network area. This drastically reduced the complexity of the range check from O(N) on the number of roboports to O(logN) on the number of rectangle union areas (which is significantly smaller than the roboport count).

Example of a huge roboport network area showcasing the complexity addressed by the rectangle union optimizationExample of a huge roboport network area showcasing the complexity addressed by the rectangle union optimization

This algorithmic improvement has made the “is it in this network” check essentially free in terms of performance cost. This significant speedup has allowed the developers to increase the rate at which construction robot tasks are checked in 2.0, aiming to alleviate the “600 jobs missing” alerts and provide a smoother construction robot experience, particularly on large dedicated servers and player-built megabases.

These are just a few examples of the under-the-hood improvements coming to Factorio dedicated servers in version 2.0. These changes, focusing on stability, server management, and performance, will contribute to a better overall multiplayer experience for server hosts and players alike. As always, your feedback and experiences are valuable, so be sure to share your thoughts on these improvements in the usual community channels.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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