bergerhealer / TrainCarts

Minecarts redefined
MIT License
205 stars 63 forks source link

Configuration Option for Permanent Chunk Loading to Reduce I/O Pressure in Train Carts #496

Open fjybiocs opened 8 months ago

fjybiocs commented 8 months ago

Feature Request

Configuration Option for Permanent Chunk Loading to Reduce I/O Pressure in Train Carts

Description

Hello, I've noticed that Train Carts has a very high time consumption on the CraftWorld.getChunkAt() event (24%), which may cause server lag. I suspect that CraftWorld.getChunkAt() might involve I/O operations, leading to high latency.

On my server, there is a long railway line, and the trains running on this line are set to force load chunks, and trains are automatically generated at regular intervals. I wonder if the frequent loading and unloading of chunks leads to intensive I/O operations, causing lag.

Therefore, I would like to know if Train Carts offers such a configuration: setting the chunks that trains frequently pass through to stay in memory permanently to reduce I/O pressure. Because I have sufficient memory space to do this.

If there is no such configuration option, I wonder if it could be considered to add such an option. This could significantly improve the performance of servers using the Train Carts railway system as their main gameplay, by keeping the chunks along the railway line in memory permanently, reducing the number of I/O operations.

Examples

For example, set a maximum number of permanent chunks and use the LFU (Least Frequently Used) algorithm to evict permanent chunks.

RyanHecht commented 8 months ago

My gut tells me that this is out of scope for TrainCarts, and should likely be its own plugin. BKCommonLib's ChunkUtil has some forceChunkLoaded convenience methods that folks looking to implement this for themselves may want to use

RyanHecht commented 8 months ago

I guess you could make the argument that rails could have a keepChunksLoaded property similar to carts? I could see that being added to TC-Coasters but not sure if there's infrastructure to easily do that for vanilla rails in TC proper

bergerkiller commented 8 months ago

I have considered making a very simple plugin that simply uses bkcl's ForcedChunk API to keep parts of the world loaded. Chunk loaders are some of the easiest things to make.

A problem is though, a server only has so much memory, and when people plop down a chunk loader with radius a billion it kills the server.

bergerkiller commented 8 months ago

Probably if it works like in modded where a particular block automatically keeps stuff loaded, and this works with worldedit and such, then people can incorporate it into their builds (under the track for example)