Mature Posted January 9, 2020 Share Posted January 9, 2020 Hello community, my first post here! : D, I'm creating a server that involves a lot of players and whether or not I want to work with a lot of information, I've been thinking and how my scripts will use a lot of player tables where they pull everyone from the server if instead of putting the for in server ', the player must process and select the elements and send them to the server, to the server role instead of checking and finding the elements he only needs to send information to the players. Can this improve machine and server performance? Server function localC (thePlayer, _, message) if message then triggerClientEvent(thePlayer, "processClient", root, message) end end addCommandHandler("local", localC) Client addEvent("processClient", true) addEventHandler("processClient", root, function (message) x,y,z = getElementPosition(getLocalPlayer()) for theKey,players in ipairs(getElementsByType ( "player" )) do xP,yP,zP = getElementPosition(players) if getDistanceBetweenPoints3D (x , y, z, xP, yP, zP) < 20 then triggerServerEvent("sendMessage", localPlayer, localPlayer, players, message) end end end) Server addEvent("sendMessage", true) addEventHandler("sendMessage", root, function (thePlayer, player, message) outputChatBox(getPlayerName(thePlayer).." Send: "..message, player, 255,255,255, true) end) Link to comment
Scripting Moderators ds1-e Posted January 9, 2020 Scripting Moderators Share Posted January 9, 2020 (edited) 43 minutes ago, Mature said: Hello community, my first post here! : D, I'm creating a server that involves a lot of players and whether or not I want to work with a lot of information, I've been thinking and how my scripts will use a lot of player tables where they pull everyone from the server if instead of putting the for in server ', the player must process and select the elements and send them to the server, to the server role instead of checking and finding the elements he only needs to send information to the players. Can this improve machine and server performance? Server function localC (thePlayer, _, message) if message then triggerClientEvent(thePlayer, "processClient", root, message) end end addCommandHandler("local", localC) Client addEvent("processClient", true) addEventHandler("processClient", root, function (message) x,y,z = getElementPosition(getLocalPlayer()) for theKey,players in ipairs(getElementsByType ( "player" )) do xP,yP,zP = getElementPosition(players) if getDistanceBetweenPoints3D (x , y, z, xP, yP, zP) < 20 then triggerServerEvent("sendMessage", localPlayer, localPlayer, players, message) end end end) Server addEvent("sendMessage", true) addEventHandler("sendMessage", root, function (thePlayer, player, message) outputChatBox(getPlayerName(thePlayer).." Send: "..message, player, 255,255,255, true) end) In my honest opinion this would be worse, you are just complicating it, but before that. 1) Don't attach events to root, use resourceRoot instead - this is sufficient if event is handled by same resource, as wiki says events attached to root are very CPU intensive (client/server) 2. getLocalPlayer() it's a function call which returns local player, you should use existing predefined variable localPlayer instead. 3. Use client predefined variable on server-side, when using events - https://wiki.multitheftauto.com/wiki/Script_security 4. ipairs it's slowest loop you can use. You might use integer loop which is fastest loop: local players = getElementsByType("player") local player = nil for i = 1, #players do player = players[i] -- it's your player end I understand you, and your trial to improve an server/client performance, i'm one of those persons which care about that. To the point, the way you presented above could by replaced by simply server-side check for players around (i suggested possibility to add table as receiver instead of looping players, hope someone would do it) rather than sending informations to client and sending it back to server. Passing data between sides seems to be more expensive. If i am wrong, i'm pretty sure IIYAMA could correct me. Edited January 9, 2020 by majqq Link to comment
Moderators IIYAMA Posted January 10, 2020 Moderators Share Posted January 10, 2020 (edited) 10 hours ago, Mature said: Can this improve machine and server performance? No. The event system is a key component in MTA that should be well maintained. This is absolutely killing performance CPU as well as bandwidth: for theKey,players in ipairs(getElementsByType ( "player" )) do -- triggerServerEvent("sendMessage", localPlayer, localPlayer, players, message) -- end If you want to optimise this, then use 1 trigger event with a list of players. But still wasting bandwidth like this, will result in network issues and text delays. So my recommendation: - Do everything serverside. - Use this function to collect the players: https://wiki.multitheftauto.com/wiki/GetElementsWithinRange (Cube, not sphere) - Compare the distance as you were already doing for accuracy results. - add a spam filter - add a limit how many messages a player per second can send. - only display an X amount of messages per Xms, the rest will have to wait in a buffer. So that server lag will be limited to only text lag. Edited January 10, 2020 by IIYAMA Link to comment
Mature Posted January 10, 2020 Author Share Posted January 10, 2020 13 hours ago, IIYAMA said: Não. O sistema de eventos é um componente chave no MTA que deve ser bem mantido. Isso está absolutamente matando a CPU de desempenho, bem como a largura de banda: Se você deseja otimizar isso, use 1 evento de gatilho com uma lista de jogadores. Mas ainda desperdiçar largura de banda como essa resultará em problemas de rede e atrasos no texto. Então, minha recomendação: - Faça tudo no servidor. - Use esta função para coletar os jogadores: https://wiki.multitheftauto.com/wiki/GetElementsWithinRange (Cubo, não esfera) - Compare a distância que você já estava fazendo para obter resultados precisos. - adicione um filtro de spam - adicione um limite de quantas mensagens um jogador por segundo pode enviar. - exibir apenas uma quantidade X de mensagens por Xms, o restante terá que esperar em um buffer. Portanto, esse atraso no servidor será limitado apenas ao texto. Thanks. 23 hours ago, majqq said: Na minha opinião sincera, isso seria pior, você está apenas complicando, mas antes disso. 1) Não anexe eventos ao root, use o resourceRoot - isso é suficiente se o evento for tratado pelo mesmo recurso, pois o wiki diz que os eventos anexados ao root consomem muita CPU (cliente / servidor) 2. getLocalPlayer () é uma chamada de função que retorna um player local; você deve usar a variável local predefinida existente existente. 3. Use a variável predefinida do cliente no lado do servidor, ao usar eventos - https://wiki.multitheftauto.com/wiki/Script_security 4. ipairs é o loop mais lento que você pode usar. Você pode usar um loop inteiro, que é o mais rápido: Compreendo que você e seu teste para melhorar o desempenho de um servidor / cliente, sou uma daquelas pessoas que se preocupam com isso. Na verdade, a maneira como você apresentou acima pode ser substituída por uma simples verificação no lado do servidor para jogadores ao redor (sugeri a possibilidade de adicionar uma mesa como receptor em vez de repetir jogadores, espero que alguém o faça) em vez de enviar informações ao cliente e enviá-las de volta ao servidor. A transmissão de dados entre os lados parece ser mais cara. Se eu estiver errado, tenho certeza que IIYAMA poderia me corrigir. Thanks. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now