Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 38

Thread: KoLmafia using up lots of CPU

  1. #1

    Default KoLmafia using up lots of CPU

    I didn't notice exactly when it started happening, but recently KoLmafia has been using up large amounts of CPU after running (including 30+% CPU when idle). Clicking the "Collect Garbage" button seems to reset the CPU back to ~0%, but if I use it to automate anything again, it goes back up to 30% and stays there. This results in not only slowing down KoLmafia drastically but also causes my fan to run really loudly.

    I download the latest build from http://ci.kolmafia.us/job/Kolmafia/ on a regular basis, so maybe it was an update that changed something?

    I would like to know if anyone else has had this issue and whether there is a known fix.

    Thanks,
    Zyro

  2. #2
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,026

    Default

    People have reported something that might be similar but no one has gotten to the bottom of it. And not everyone sees similar behavior.

    I'm not sure how I would debug/diagnose this even if I were setting at your computer. The first thing that comes to mind is that the total amount of resources needed to run KoLmafia and everything else you run at the same time approaches the capacity of your hardware.

    What OS are you running? How many cores does your machine have? How much memory?

    If you run TaskManager or the equivalent is KoLmafia the only process that is consuming significant CPU (more than 5%) or is it one of many. For example, Firefox often is a resource hog on my system and in a relay browser situation it makes a difference whether it is KoLmafia (Java) or the browser that is consuming the resources.

    Are there processes that are using a significant amount of memory, possibly including KoLmafia? Does KoLmafia's memory use increase?

    It has been a long time since I had to micromanage Java's memory use. My recollection is the operating system allocates memory and Java manages it. If Java needs more it either asks and receives or aborts with an out of memory error. What you describe sounds like Java memory management but it is not clear whether Java is (on its own) Garbage Collecting a lot or what.

    Grasping at straws, there are two numbers in the "GC counter". Does the second one ever change? Does the first one go up and down as you automate but don't touch the GC button?

    I'm thinking this is an issue with your environment and adding a lot of new items (Pokefams, for example) to KoL pushed your system to the limit, but I don't know so this is nothing more than speculation.

  3. #3

    Default

    Hi fronobulax,

    Thank you for the response. Let me try to answer your questions in order.

    I am running Windows 10 on a Microsoft Surface Book with Performance Base. It has 2 cores and 16 GB of ram. I would be surprised if my hardware were the issue, since in the past I have had no problems running KoLmafia on the same machine (and even earlier ones).

    I often have a lot of programs up and running, but again, it's always been this way and I haven't encountered this issue previously. Here is a screenshot of my Task Manager right now that shows the situation: https://i.imgur.com/FoYTefW.png

    All I did to trigger the CPU increase in KoLmafia was type the line "/count freddy k" in the gCLI. I guess I don't have to be automating something for this to happen - doing almost anything in KoLmafia appears to trigger it.

    As far as I can tell, the second number in the GC counter does not change.

    I do not know what my environment means, but if it's relevant at all, I have not done the Pokefam path yet.


    EDIT: Based on my (admittedly limited) testing, doing things in the relay browser does not cause the CPU to increase, while doing things in the KoLmafia program usually triggers the increase after only a couple actions.
    Last edited by Zyro; 04-24-2018 at 05:35 PM.

  4. #4
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,026

    Default

    So I actually paid attention to Task Manager while running. Windows 10, 8 core, 16 GB. CPU was generally under 10% and no signs of memory issues, with one exception. The character running Veracity's Meat Farming script with BestBetweenBattles enabled was seeing CPU close to 20% and after a while the fan came on. So there may be something there.

    Your screen grab does not suggest any memory issues although it would be interesting to see what changes if Chrome and Firefox were not sucking up so much memory. It would also be interesting to see what happened if Java were given more memory when it started. That's probably a Windows 10 setting although I have not researched where it can be changed.

    I will ponder.

  5. #5

    Default

    Thanks, hopefully it can be figured out.

    If anything changes, I will post an update here.

  6. #6

    Default

    Based on (again) limited testing, it seems that using the .exe program found here: https://sourceforge.net/projects/kolmafia/ does not cause the high CPU issue, but using the .jar file found here: http://ci.kolmafia.us/job/Kolmafia/ does.

    I have to use the .jar file because I have a weird scaling issue that makes KoLmafia super tiny on Windows 10 (it's described here: https://www.reddit.com/r/kol/comment...ia_to_work_in/). There is a fix mentioned in a link on that thread, which I've applied, and it only fixes the display problem for the .jar file and not the .exe.

    I recently installed a Java update, so I don't know if that could possibly be the cause of the CPU issue.


    EDIT: I did a little bit of digging online and saw garbage collection mentioned several times regarding high CPU usage for a Java program. Since clicking the GC button in KoLmafia appears to be a temporary fix, I feel that this is definitely somehow related (though I have zero technical expertise on this subject).

    Also, typing "/count anything" in the gCLI will trigger the high CPU usage without fail for me.
    Last edited by Zyro; 04-25-2018 at 06:13 AM.

  7. #7
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,026

    Default

    The .exe from SourceForge was updated in December whereas the jar file from KoLmafia.us is built from the most recent code available. It is possible that changes to KoL that are reflected in KoLmafia (new items, etc.) could account for the difference. But it is also possible, if this is a memory issue, that Windows allocates more memory for the .exe than the .jar.

    I have solved the scaling issue and commented on it KoLmafia.us. Try searching on HDPI or DPI but it is basically the reddit solution. It can be applied to the .exe with a little digging but, to be honest, I'll never run the .exe and it is not worth the effort.

    Generally Java only does garbage collection when it needs memory or there is a lot of garbage. So one quick test would be to try and tell the operating system to start Java with more memory. I cannot trivially find the default settings for Windows or how to change them at the OS level, but if you open Windows cmd, change to the directory that contains the jar file, (and presumably all your mafia files) and type

    Code:
    java -Xms256m -Xmx2048m -jar KoLmafia-18577.jar
    that will run mafia with a known amount of memory. You should use change the jar file name parameter to match the version you have. Depending on how you implemented the HDPI fix you may find this launches tiny screen mafia (in which case find java.exe and add a manifest file there, assuming you understand the fix). You should not have to change the 2048 unless you get an out of memory abort or the operating system complains it can't allocate that much. The key is the 256. If you really have a garbage collection problem then increasing "the 256" should result in less GC and possibly address your problem. I suspect the 256 might be higher than your system's default is so try that first.

    It is good to know that /count is a culprit. What is it supposed to do? I have a vague recollection that slash anything in the gCLI invokes a chat command that is "native" to KoL but since I take a perverse pleasure in ignoring all things chat as much as possible I will plead ignorance :-)

  8. #8

    Default

    I do not know how to use the command prompt to change to the directory with mafia, but I did follow the instructions here to allocate more memory to Java: http://www.messiahpsychoanalyst.org/...ory_in_Windows Unfortunately, it did not solve the issue, as another "/count " made the CPU jump up to 20-30% as usual.

    /count is a chat command that counts the number of an item in your inventory. I was only using it as an example of a basic command that causes the problem - other gCLI commands do the same thing (e.g., https://i.imgur.com/J0WZewN.png). Perhaps interestingly, after I reset the CPU and ran a script from the scripts menu, the CPU stayed normal (so not everything causes the CPU to increase).

    Doing anything in the gCLI does appear to always trigger it, and based on what I've noticed, automating turns will also trigger it.

  9. #9

    Default

    Also, fwiw, typing "gc" in the gCLI causes the first number in the GC counter to oscillate up and down and triggers the CPU increase.

  10. #10
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,791

    Default

    other gCLI commands do the same thing
    Originally Posted by Zyro View Post
    That also shows a chat command. Does it only happen after using chat commands (AFAIK anything that starts with / is essentially passed to kol's chat system somehow?), or normall mafia commands (for something that will probably hit the server, try ... hmm ... putting something in your DC? or searchmall? or refresh all?)
    (to be clear: I am now asking if this happens even if you *never* use a chat command in the gCLI)


    Also, fwiw, typing "gc" in the gCLI causes the first number in the GC counter to oscillate up and down and triggers the CPU increase.
    Originally Posted by Zyro View Post
    That's probably normal. GC is always CPU work. Unless it takes longer than half a second or so.

    To me, this sounds a little like what I sometimes see on out work windows machines - there still seems to be RAM free, but the system starts swapping like hell for some reason. With a SSD you wouldn't even hear it (and with a modern thin thingy there wouldn't even be an activity light).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •