Content: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Background: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Notes Sharp Wood Rockface Leather Honey Vertical Triangles
Welcome to TerraFirmaCraft Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

  • Announcements

    • Dries007

      ATTENTION Forum Database Breach   03/04/2019

      There has been a breach of our database. Please make sure you change your password (use a password manager, like Lastpass).
      If you used this password anywhere else, change that too! The passwords themselves are stored hashed, but may old accounts still had old, insecure (by today's standards) hashes from back when they where created. This means they can be "cracked" more easily. Other leaked information includes: email, IP, account name.
      I'm trying my best to find out more and keep everyone up to date. Discord (http://invite.gg/TerraFirmaCraft) is the best option for up to date news and questions. I'm sorry for this, but the damage has been done. All I can do is try to make sure it doesn't happen again.
    • Claycorp

      This forum is now READ ONLY!   01/20/2020

      As of this post and forever into the future this forum has been put into READ ONLY MODE. There will be no new posts! A replacement is coming SoonTM . If you wish to stay up-to-date on whats going on or post your content. Please use the Discord or Sub-Reddit until the new forums are running.

      Any questions or comments can be directed to Claycorp on either platform.
Sign in to follow this  
Followers 0
InsaneJ

Tile entity tick reduction

7 posts in this topic

Running a large server we see that TFC uses a lot of tile entities for it's core gameplay mechanics. In single player and smaller servers the current way tile entities work don't cause too many issues. But having 10.000+ causes a large strain on even the (currently) most powerful hardware. And even if load isn't an issue, there are issues with Minecraft itself that just can't handle really large amounts as observed by running the Warmroast profiler during a mass disconnect event happening on our server:

We used Warmroast, a Java profiler aimed towards Minecraft, to track down what is keeping the server occupied. It seems that during a mass disconnect the server is busy processing a lot of tile entities. The server has upward of 15.000 tile entities loaded during peak hours. In the screenshot below you can see that

net.minecraft.world.WorldServer.func_72939_s() is using 82.79% CPU time during a mass disconnect on the server. It looks like it's going through a very large array and deleting items from it. If this takes too long (1200) it dies, which seems to be when the mass disconnect occurs.Posted Image

 

Many TFC processes are dependent on how many ticks something has been busy. For example crops on tilled soil and cooking a pork chop in a fire pit take X-amount of ticks to complete. Would it be possible to change this behavior (perhaps for TFC 2) so that these tile entities don't tick 20 times per second but maybe twice and then compare world time to determine progress?

 

In our server we can for example specify how many ticks any given tile entity skips so we could force them to only tick twice per second. However that causes problems if a workload is counting ticks. A pork chop would take 10 minutes to cook instead of 1.

 

Thank you for your consideration.

1

Share this post


Link to post
Share on other sites

Tile entities always tick 20 times per second. This is hardwired mojang code and no amount of coding on our end can change that. All that we can do is attempt to optimize our own code to make sure that the least amount of code as possible is running during each of those ticks, which we strive to do anyways. Most Tile Entities in TFC already use a timestamp process to prevent execution of large blocks of code(With the exception of cooking type ticks which need to happen immediately. Even Decay only ticks one time per hour.). Crops for instance only run their code at noon unless they are being loaded from an unloaded chunk. At which point they have to play catch-up for all of the noons in which they were unloaded. If you can find specific tile entities that are causing mass lag, we'd be happy to take a look, but other than that we already attempt to curb the issue you're referring to.

0

Share this post


Link to post
Share on other sites

Thank you for the explanation.

We'll go take a look and see if we can pin point exactly which (if any) tile entities use a lot of cpu time. On that comes to mind, or at least I've heard people mention, is anvils. They seem to take up a fair amount of CPU even if they aren't actively being used. We'll report back.

1

Share this post


Link to post
Share on other sites

I did limited profiling of the anvils. I tested stone, copper and steel anvils. I tested them with their tier of hammer, flux, copper ingot and a stick. I did not see any difference between any of the anvils, which is expected, so I'll only give the numbers based on what was in them. It should be noted that the timing for 2 anvils is not twice the timing of 1 as they share some calculations.

I profiled with Opis in a clean world with latest TFC, forge 1236, Fastcraft 1.12 (forgot to update to 1.16) and up to date NEI stuffs.

A hammer being in the anvil had no effect in any test and so is present in every test. Anvil with hammer were <10us. Anvil with flux (full or partial stack were the same) ~150us. With copper ingot (plan selected or not had no effect) or stick in working slot ~500us. Copper ingot/stick with flux 600-1000us. There was lots of variation in this reading, but it was always greater than without flux.

I also tested items in welding slot and so no effect. The variation and maximum value seemed to increase the longer client was open so I reloaded client often. When I have time I'll profile an anvil with ingot and flux over time.

So guess a lesson for server owners is to educate your players to not leave anything in working slot if they aren't using anvil. Even better if you can get them to remove flux as well. To give a scale I was seeing timing of ~40us for a chest.

For those who don't know what these numbers mean. They are a calculation of how much of the computing time the tile entity is taking. You have 20 ticks per second and calculations are initiated every tick, so every 50 milliseconds. This means that the CPU has 50ms to complete all its calculations. So you take the time it takes for each calculation and add them up. If the sum is 50ms or less then your game/server will run at 20 ticks/second (tps). If the sum is more than 50ms then it can't initiate the next tick until all the calculations are done, so you can no longer get 20 ticks in a second. So under 20tps aka lag.

1

Share this post


Link to post
Share on other sites

Hey Bunsan Thanks for the explanation on the CPU calculations. Would it be possible to post some advice that we could share with our player to avoid LAG? We don't have much problems now, but it's always good to prepare.

0

Share this post


Link to post
Share on other sites

There isn't much in base TFC that is a big issue that is different than Vanilla. Basically you want to base you rules/suggestions based on the size of your playerbase and power of your server. There is no point annoying your players if there isn't a issue in server function.

The great thing about TFC is the scarcity and difficulty of acquiring materials prevents the silly excess you see in the overstuffed Modpack servers. I will say that on a normal modded server I'd be very concerned about a TE with 1000us reading, but for TFC it isn't an issue as there aren't the intensive TEs. However I haven't bothered looking into TFC items. I'll poke a bit and see what I can find later. All I could suggest for your server is for players to try to not leave items, beyond hammer and flux, in an idle anvil. It isn't worth annoying them too much with this unless you are seeing TPS issues.

To give perspective by far the worst lag causing block on our 1.6.4 200 mod server was the vanilla hopper. Highest timing on one I've seen is 2000us.

1

Share this post


Link to post
Share on other sites

So did a bit more testing. Over time the cpu time for anvils is stable, there is just variation in the samples. So I tested mass quantities of anvils. The long and the short of it any more than 10 anvils loaded you will see an average of 645us of CPU time per anvil. Below 10 anvils and it starts creeping up, until it reaches an average of 700us for a single anvil. So I would assume that about each individual anvil does about 645us of calculations and about 55us of calculations is a global thing irrespective on number of anvils, but that is just a guess.

 

Tested other things as well and they are all negligible. Pretty much everything at its peak was 10us or less. Only acceptation was food prep which empty is 3us and full is 20us, so still completely negligible.

 

So the long and the short of it is that beyond vanilla issues, i.e. chunk generation, silly RS stuff, etc., TFC is incredibly light for running. The only situation you would see an issue is on a server where you have a ton of anvils loaded at the same time that have something in their working slot.  

1

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0