Discussion in 'Development' started by Sergey Dertan, Mar 11, 2019.
I need to send packets with large strings which make lags, can I do it async?
You can't use instances on async tasks, use these tasks to arsort, foreach(scandir("folder with lots of files")), etc. If you are editing some of the strings before you send the packet, then it's possible to make it edit asynchronously. What are you trying to do?
What packets are you sending? You might want to use a BatchPacket (my knowledge on the protocol is outdated for 2 years, so don't quote me)
You might want to recheck if that's what makes it lag. It doesn't sound like something that would cause a whole lot of lag on itself, unless of course you do intensive computing to produce the strings.
I need to send large text packets to each player each second(up to 300 symbols), as I know it's taking much time to encode packets so I want to send them async
So have you checked if it's actually a problem? Don't prematurely optimise.
Yes, without this task I have no lags
Yes so perhaps show the code so we can help you find what is actually causing this.
If you're trying to send a player messages, why use text packets directly and not use the built-in function called sendMessage()?
One 300-character text packet per second is pretty small. One SetEntityMotionPacket takes uvarint+uvarlong+lfloat*3 = approx. 16 bytes, and it gets sent per entity per tick (I think so), which multiply up to way more than 300B/s. I don't think sending the packet itself is the source of lag.
BTW make sure you're talking about server-side lag not client-side lag. Does the TPS actually decrease?
Please show the code of this task that seems to create lag so that we can help find out what's causing the lag.
Separate names with a comma.