Jump to content

General advice for debugging slow/unresponsive scripts?


Impensus

Recommended Posts

Hi guys,

I recently made a big expansion to a script of mine. I went from the classes Farming, Banking & Teleports to a script that contains about 13 classes total. The reason I mention this, is that since then my script eats about 500mb RAM (fair bit more than it did originally) and is sometimes unresponsive/takes a while to stop.

I've noticed this behaviour even when the script is looping in the "Farming" methods, despite this behaviour not existing before the additional classes were added. No changes have been made to the original classes so I am unsure why they now are a lot slower. I'm wondering if you guys have any generic tips/anecdotal advice on problems you have encountered causing similar behaviour.

Thanks!!

Link to comment
Share on other sites

My best go-to's are to comment everything new and then uncomment it piece by piece so you know what works well, and then just log everything and track the log to see what is being logged during a period of lag/freezing.

You could be calling something an unreal amount of times and not know it, creating an object over and over, not caching info efficiently, or not creating optimal methods/loops in general.

Do you have multiple threads running, external API calls, web interfacing? Address things like that.

Link to comment
Share on other sites

I agree with Ace. This sounds like your tring to use something that is null fixing this will help the memory issue. Fixes? Try/catch around the loop this is a bandaid for gun shot or null check everthing this is just a pain in the ass but saved me many heart aches . 

Follow questions to get a better answer.

  1. Can you stop the script after sometime or do you have to force kill it if this does happen?
  2. Do can you see the log?
  3. Is it only in one section of the script or you can't tell. 

 

 

Link to comment
Share on other sites

On 6/1/2020 at 9:59 PM, Nbacon said:

I agree with Ace. This sounds like your tring to use something that is null fixing this will help the memory issue. Fixes? Try/catch around the loop this is a bandaid for gun shot or null check everthing this is just a pain in the ass but saved me many heart aches . 

Follow questions to get a better answer.

  1. Can you stop the script after sometime or do you have to force kill it if this does happen?
  2. Do can you see the log?
  3. Is it only in one section of the script or you can't tell. 

 

 

1. Sometimes if I wait the script stops. Other times I have to force kill it. I’m guessing that after I’ve ran and stopped it too many times the client eventually becomes unresponsive and needs to be killed.

2. I can see the logs, there are no visible NPEs

3. It’s likely that it is one or more sections of the script. However I don’t think it’s code that is currently running (if that’s possible) as like I mentioned in the body the code in this loop worked fine before I added new classes. I’m guessing some errors occur during class/variable instantiation that cause these errors but don’t give visible NPEs etc.

Link to comment
Share on other sites

Sorry I can't help you more. Its most likly something supper small.

17 hours ago, Impensus said:

I’m guessing that after I’ve ran and stopped it too many times the client eventually becomes unresponsive and needs to be killed.

 

Sounds like a mermory leak or a threading problem. 

If a memory leak limit recursion and making new objects.  

If a threading problem try this. (I like ExecutorSevices to kill all threads.)

Quote

private ExecutorService executor = Executors.newFixedThreadPool(5);//mine is 5 because i have 4 threads 
private Runnable runnable;
        runnable = () -> {

            if (isStoped()) {
               executor.shutdownNow();
               executorSend = null;
            }
            try {
                //1 time thread task but works like a loop
                executor.submit(runnable);
            } catch (Exception e) {
              	log(e)
                executor.submit(runnable);
            }

        };

 

 

17 hours ago, Impensus said:

I can see the logs, there are no visible NPEs

That sucks.

17 hours ago, Impensus said:

It’s likely that it is one or more sections of the script. However I don’t think it’s code that is currently running (if that’s possible) as like I mentioned in the body the code in this loop worked fine before I added new classes.

Maybe take out features add them back 1 at a time till you find the problem?

Link to comment
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...