MineMaarten / PneumaticCraft

PneumaticCraft source
Other
84 stars 51 forks source link

Drone program causing server lag, and crop farming issues #499

Open Axylxys opened 9 years ago

Axylxys commented 9 years ago

After hours of trying to make an automated crop farm and have a drone manage several crops on a field (replanting them in specific areas) i isolated a program part causing some heavy server lag (2-3sec lag every few seconds) as soon as the drone is up and running.

The puzzle pieces i used:

Start Import from inventory (Area for the chest, + filter for the seed) Right click block (area for the field) Export to inventory (Area for the chest)

Basically the point is to have the drone pick some seeds into the chest, then plant them in the area, then empty the remaining seeds in the chest. Initial goal was to repeat that several times with different seeds, as it's the only way i found to have the drone plant each seed where it belongs, rather than mess up the field and spam the same crop over all the others. It worked as expected but caused lag so i removed bits after bits until i was left with that serie above.

The chest is a vacuum chest from Ender IO, the crops are magical crops, the field is basic farmland and a 3x3 area, really nothing huge or special happening. Also, the lag remains stealthy on Opis, showing as a ping increase on the whole server rather than entity specific tick time. However there's no doubt the drone is the source, as removing/replacing it several times turns the lag on or off, though it could be interaction with some of the elements above.

Also another issue i found out, as soon as i add any kind of seed as a filter to the "right click block" function it doesn't work at all, no matter the metadata or settings of the filter itself, either in true or false position. It works on blocks such as stone or various stuff but no way with the seeds (even vanilla seeds), is there anything i'm missing there ?

All of that with the 1.7.10-1.8.2-84 version.

Thanks for reading, i hope you can give me some hints on how to make it work or avoid the lag, it's such an headache that after a whole night of testing the only way to make it work as needed ends up with lag on the server, sigh.

Edit: After some more testing, it has nothing to do with the chest itself (tried with a vanilla one, same), or the magical crops (same happens with basic seeds), and it seems the removal of the export part can fix it, so i guess it's down to the export piece that for some reason doesn't work properly in this case.

Edit 2: Replacing the Export to inventory by Drop items doesn't change anything, as well as removing the crop planting part. It seems like whenever the drone is moving something out of his inventory it causes the lag, even something as simple as taking item from a chest then dropping them 2 blocks away is lagging. I also removed all drone upgrades, no change.

MineMaarten commented 9 years ago

First of all, could you pastebin the program for vanilla seeds, so I can try to replicate? (There's a pastebin button in the programmer now :)).

Without trying it out myself I can't really think of how this can cause lag.. So some testing is necessary I think..

Second:

Also another issue i found out, as soon as i add any kind of seed as a filter to the "right click block" function it doesn't work at all, no matter the metadata or settings of the filter itself, either in true or false position. It works on blocks such as stone or various stuff but no way with the seeds (even vanilla seeds), is there anything i'm missing there ?

The Item filter of the Right Click block does not filter on the item that is being right clicked. Instead, it determines which blocks are being right clicked. So in this case that would be farmland (which results in a Dirt item filter, as farmland can't be silk touched). Or don't specify any filter obviously.

Axylxys commented 9 years ago

I will do that tomorrow as well as some screenshots of the setup and various stuff, thanks for your answer already !

Also, i feel stupid for that filter now, but that explains a lot, that's one less thing to bother.

Axylxys commented 9 years ago

So here's the detail of my setup with my latest tries. I actually removed the export to inventory part. You can see on the picture the empty 3x3 field (farmland) on the left, as well as the basic vanilla chest to the right. The other stuff on the screen isn't relevant to the bug, most of it wasn't there when i first noticed it, the game is multiplayer survival and the stuff around is just my farm spots, you can even see the other drones working well (one picks up sapling in a chest and plants them, the other one breaks sugar canes).

http://pasteboard.co/1tQ53mEV.png

The program of the drone on pastebin:

http://pastebin.com/2XrPfu1G

From that point, i place the drone nearby. As soon as it's placed, there's a 2-3sec lag (delay in opening bags or doing stuff, i usually check it by opening my ender pouch over and over). After that the time can catch up, the drone goes as planned: it flies to the chest, picks up the seeds (basic wheat seeds) from the top side, then goes to hover on the field and plant them. As soon as it's done planting the last one there's a lag again, same as the first one.

After that lag he goes back to the chest, then to the field, checking all the crops in case one is missing, then over and over again the same sequence (chest => field => chest, etc). The lag happens every time when he's done checking the field and before he goes back to the chest, that's every few seconds so it's unplayable.

That's just one exemple though with a test program that serves no purpose as itself, i had the lag as well when running a program that picked up the seeds in the chest, then dropped them 2 blocks away. Also when exporting to the chest as desribed above. I think the common denominator is when the drone goes back to the chest to pickup more seeds, it's not the planting (i removed that part on some tries) nor the export itself as shown above, there's no export in that sequence.

Also it happened when there was nothing else nearby (i had to run the farm for ressources so i added the farming stations and other drones once i gave up getting that one to work), the chest isn't connected to anything either. The most disturbing is that other drones can pickup stuff in chests just fine (such as the sapling planter on the background of the picture). I also tried with different drones running the same program, just in case that one was corrupted for some reason, same results.

That's all the details i can think about. Also the world doesn't have any weird rule, it's overworld, daylight cycle as usual, whatever, and the server is at a constant 30-35 tps despite having 250 mods, i'm usually very careful on what i'm doing so that drone is irritating, lol.

Also, thanks for the awesome interface, i noticed that pastebin shortcut earlier and it's definitely a great idea, as well as the drones in general. Only fiddling with them (as well as PneumaticCraft) for a few days and they're really fun to use, i actually plan to use them extensively for most of my base, so probably more reports to come if i find other bugs. :) Your mod is awesome and getting answers and support here is even more, i hope i'm not wasting your time with such long posts though. More than a fix for my specific issue, i hope it will help you find a bug or something wonky in the code, as i suspect there's something very special going on there, i'm down to such a basic setup other peoples should have encountered it before. Strange stuff.

MineMaarten commented 9 years ago

This is veeery peculiar.....(5 mins later) WAAAIIIT I might have it! I bet there is no block under the chest? I'm quite certain there isn't. If that's the case, that's causing the lag. Here's why:

When a Drone tries to pathfind over to an inventory, it's trying to navigate to a side of the chest. It goes through all six sides, starting from the bottom. It takes the block under the chest, checks if it's a place he can stay in (non-solid), and then tries to pathfind.

This is where it goes wrong, as there is no way to get to that one block place. To come to this conclusion it takes quite a bit of server resources. When it finds out it fails, it will try the other sides. The top works out fine, and that's what it uses.

This doesn't happen often where a chest isn't reachable from the bottom but is from the top. If the chest is not reachable at all, the drone will simply teleport (at a high air cost). If users notice this they usually change their set-up until the drone can navigate to the chest in a normal way.

The pathfinding mechanic itself can't be altered (it's Vanilla's pathfinding). Therefore, the lag caused on a single pathfinding fail can't be fixed. However, after this, I might look at making the Drone remember which side of an inventory was successful in its pathfinding, and try that side first next time it uses the inventory.

To be continued.

(also, let me know if this indeed was the case, and if placing a block under the chests fixes the issue)

Axylxys commented 9 years ago

And that is... an epic win ! You nailed it, there was indeed a hole below the chest, as i use a hollow underground to run the conduits, access machines and power the various engines around the farm. A simple stone block below the chest and, no lag anymore.

That's awesome, i totally didn't expect something like that. It's also very interesting to understand a bit how their pathing work. I almost had that idea, as i specified "top side" instead of leaving all the sides turned on with the Import inventory, i thought having the chest stuck inside the ground could slow down the drone sequence. But it seems it wasn't enough to prevent his pathfinding and i didn't think about that bottom slot.

Well, thanks a lot for the explanation, and i'm really impressed you found that one. That makes sense and i'll pay attention to what's under the chests now, so much hassle just because i thought it was prettier to stick the chest into the ground rather than on top of it, haha. I also noticed some oddity on the other drones, but that's a whole different topic so i'll open a new issue. Also i'm new to GitHub (registered especially for that) so not sure if i should "close" the issue or leave that to you.

MineMaarten commented 9 years ago

Cool :). The sides the drone can access purely are for simulating to see which items are accessible, they don't influence the pathfinding in any way. So it will try all 6 sides regardless.

About closing the issue, usually you can when the issue is indeed 'fixed', but in this case I might want to see if I can implement what I mentioned before, so it's nice to keep the issue open until I've implemented that or couldn't care about it ;). Still have to decide.

Axylxys commented 9 years ago

A bit more info in case this helps at some point, i encountered the same issue with drones accessing Dynamic Tanks from Mekanism and Tanks from Pressure Pipes. Both are multiblocks so it's probably the same error with the drone checking all the sides of the valve and getting stuck when inspecting the side inside the tank, as it probably can't identify the multiblock and it appears as an empty box. I suspect this could happen for all multiblocks from various modes.

Probably not much to do about that, i fixed it easily by sending the liquid first into a drum next to the valve and have the drone interact with that instead of the multiblock itself, but that report will hopefully help someone with the same issue !

MineMaarten commented 9 years ago

It just underlines the need of the fix I had planned ;)