Sylvek Posted November 27, 2017 Share Posted November 27, 2017 (edited) Hi! I scripted function that makes loop which gets result from MySQL and put this to gridlist. It's like refresh button which loads items for sale. Problem is that one use of this button take about 0.25% server CPU usage. Bigger problem is that I can spam this button and it takes about 10% of server cpu usage. Don't know if it's normal or too high. Could you help me and say how to decrease this and it's normal? Edited November 27, 2017 by Sylvek Link to comment
Moderators IIYAMA Posted November 27, 2017 Moderators Share Posted November 27, 2017 Write one query to get the result, not 100000. Link to comment
Sylvek Posted November 27, 2017 Author Share Posted November 27, 2017 I am doing like you say. local result = exports(dbquerry) etc. And doing loop like this For i,v in pairs(result) do Link to comment
Moderators IIYAMA Posted November 27, 2017 Moderators Share Posted November 27, 2017 (edited) Show the query you are using. Solutions: You might want to use a callback, because the lua code will pause when you execute the query(if no call back). (which can cause a lot of lagg if the requested data size is very large) Save the data you collected inside of a table(as buffer). Use tickcount to decide if you re-call the mysql database or use the buffer. (which can improved your performance with 100 t/m 1000%) So if a guy is spamming/pushing the button a lot of time, your cpu usage will stay normal. Improve your query and set a: LIMIT 1000. Which will make sure that you do not overheat your database. You might not get all the results you need, but you can also request more later, see this example: https://stackoverflow.com/questions/5767479/mysql-limit-range Edited November 27, 2017 by IIYAMA Link to comment
Sylvek Posted November 27, 2017 Author Share Posted November 27, 2017 I am not at computer at this moment but it's like that: local result = exports(DB,dbQuerry(select * from table where owner = ?,owner) Link to comment
Moderators IIYAMA Posted November 27, 2017 Moderators Share Posted November 27, 2017 Is there always 1 data per owner? Or can there be more data per owner? Link to comment
Sylvek Posted November 27, 2017 Author Share Posted November 27, 2017 There can be more data. Link to comment
Moderators IIYAMA Posted November 27, 2017 Moderators Share Posted November 27, 2017 Your query looks fine. I hope the solutions will help you with solving your problem. 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