Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Pre Note: Prepare for huge wall of text.

 

I came across a major bottleneck when implementing certain features into my mod

 

here is the basic gist of what I am doing and wanted some input if your a player/server owner or other inputs.

 

Lets say on a server there are 10 players

each player is queued to drop 64*100 items each so each player drops 6400 items

so 10 players would drop 64,000 items

 

I thought about dropping the items individually but obviously on single player or multiplayer would grind to a halt if all these items were drooped at once.

 

So just to make this less of a strain it doesn't drop individual items and will do its best to drop the maximum amount of items in one stack

 

so rather than dropping 64,000 individual items it drops 6400 itemstacks still would probably cripple most games.

 

I then thought well if I made a list of items to drop and then for each stack of 64 items it would drop in 10 ticks from its previous player (ticks is based on player not globably)

 

so when dropping 6400 itemstacks it would take 1000 ticks over 50 seconds

 

obviously this is still very intensive on a server over 50 seconds but its better than dropping them all in one tick

 

an expansion to this is that I keep a global on how many global items will drop in the next x ticks and change the tickrate (will get onto this in a second) of the items to be dropped increasing in 1 tick when certain parameters are met.

 

I then came into yet another problem to check when an itemstack needs to tick

it would have to iterate over 6400 items in a list and tick each individual item which could cause a tick to last 2 seconds so for every tick which is meant to be 1/20th of a second it would take 200/20th of a second to tick which would be bad for big servers.

 

I then came up with threading itemdrops.

 

when an item needs to drop it will be added to a blockingqueue to stop conncurent thread editing of variables, nasty stuff.

 

so then in the new thread that stops itself when it has nothing more to tick until its re started later by another player wanting to drop items

 

the main minecraft thread will add to the blocking queue and ask that the dropping thread pause until adding to the blockqueue has finished so that the main thread doesn't hang while waiting to put items into the queue

 

the second thread runs every 1/20th of a second obviously this thread doesn't take into account the main thread so it could be running faster than the minecraft thread or slower.

 

this second thread will peak and then grab an itemstacks to tick and when the item needs is to be ticked next tick it will add it to a different blocking queue that the main thread picks up and then drops the item on the next tick (have to pass it back to another blocking queue because I cannot drop the item directly from the other thread because of concurrency issues.

 

so a breakdown:

a) depending on how many items need to drop it will increase the amount of ticks between item drops minimum 10 ticks spacing between each item drop.

b) tries to make the biggest itemstack for that player as to lower entity counts.

c) ticks itemTick countdown on another thread so that the mainthread can continue to run without sticking on the iteration

d) stops thread when not needed

 

What I wish to know is whether or not there is a better solution to this that would cause the least amount of lag as possible on the main thread and maybe even decrease lag on the secondary thread.

 

the example I use is extreme, there are config settings so the user can set it to whatever they want if they want to set it ridiculously high as these examples show then that is their stupidity for allowing it but I would still be welcome to finding a cheaper solution

 

big wall of code over now for the big wall of code :D

 

UtilsItem class

 

Reveal hidden contents

 

 

when the above object has been finished with its sent to Utils.dropItem()

 

Reveal hidden contents

 

 

specifically if (doTickCallBack == true) ServerTickHandler

.addDropItemQueue(new DropItemQueue(maxTicks, p, itemstack));

 

will call in my serverTickHandler

 

Reveal hidden contents

 

 

DropItemHandler class

 

Reveal hidden contents

 

  • Author
  On 3/21/2013 at 1:13 AM, Jdb100 said:

just a question but why not just give them the items instead of dropping them

 

because math

 

player invent = 28

if dropping 100 stacks that's 72 stacks either lost because no room OR I still drop the 72 stacks.

 

not a solution but thanks for taking the time to read this.

 

  • Author
  On 3/21/2013 at 10:32 AM, diesieben07 said:

Dropping 100 stacks per player doesn't seem like a good idea to me. Not only from a performance point of view (even if you spawn them delayed, ticking that many Items can easily kill a server), but also from a usability POV. What should a player do with these 100 stacks? manually insert them into a chest? Wait for them to despawn? seriously, I think you need to review your idea :D

 

By ticking the items do you mean ticking them from the main thread or the secondary thread?

 

I chose 100 stacks as a over shoot because I have to take into account the "stupid" people that take advantage of the config settings.

 

by default its only around 5-6 stacks but if the end user really wanted to they could they could change it to drop a trillion stacks (if they have enough ram)

 

From an end user point of view that's totally up to them what they change their settings to.

 

Why I created this thread was to make it the most efficient on resources as possible.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.