Code Monkey home page Code Monkey logo

Comments (12)

darkstar avatar darkstar commented on August 21, 2024 3

I have the same issue and fixed it by reducing the load in the main busy-waiting loops.

Try this patch:

diff --git a/py-kms/pykms_Server.py b/py-kms/pykms_Server.py
index 80c182a..2a1638d 100644
--- a/py-kms/pykms_Server.py
+++ b/py-kms/pykms_Server.py
@@ -10,6 +10,7 @@ import logging
 import os
 import errno
 import threading
+import time

 try:
         # Python 2 import.
@@ -57,6 +58,7 @@ class server_thread(threading.Thread):
                                     self.is_running = False
                                     self.server = None
                             self.queue.task_done()
+                    time.sleep(0.1)

 ##-----------------------------------------------------------------------------------------------------------------------------------------------

@@ -249,6 +251,7 @@ class kmsServer(socketserver.BaseRequestHandler):
                                 loggersrv.info("Responded to activation request.")
                                 ShellMessage.Process([-3, 18, 19]).run()
                                 break
+                time.sleep(0.1)

         def finish(self):
                 self.request.close()

ZIP file:
pykms-reduce-cpu.zip

from py-kms.

SystemRage avatar SystemRage commented on August 21, 2024 1

I investigated problem and i noted that's dependent on how docker container is created.
So i created a docker container in this way:
1
and visualized some things:
2
Actually there's a cpu overload. (with commands sudo docker stats --no-stream and sudo docker exec -ti container_id top)
3
Then i created another docker container with -it option, and this doesn't suffer the same problem.
View previous image and top command result:
4
I tested that py-kms process runs good with:

sudo docker exec -ti container_id bash
python3 pykms_Client.py 0.0.0.0 1688
cat /var/log/py3-kms.log

and then exiting from bash:
sudo docker logs container_id

Note: environment variables must be called before container ID, so run-py3-kms.sh, run-py2-kms.sh and docker readme require correction.

I await feedback.

from py-kms.

ackurdeeve avatar ackurdeeve commented on August 21, 2024

me too...have to kill it to recover. I used it on GCP.

from py-kms.

SystemRage avatar SystemRage commented on August 21, 2024

Mine.
terminal

from py-kms.

vosdev avatar vosdev commented on August 21, 2024

@SystemRage Can you start up the python3 docker container? That's how i am running it. On a fully up to date ubuntu 18.04, docker 18.09-6

I put LOGLEVEL=DEBUG but there is no logging at all

from py-kms.

vosdev avatar vosdev commented on August 21, 2024

Yeah that reduces the load for me. Ugly workaround but hey it works :)

from py-kms.

vosdev avatar vosdev commented on August 21, 2024

Mine.
terminal

With the sleep in the while loop the 100% CPU usage is gone. Could you run the pykms_Server.py in a docker container?

from py-kms.

vosdev avatar vosdev commented on August 21, 2024

Seems to work pretty well 👍

from py-kms.

williamsmt avatar williamsmt commented on August 21, 2024

I'm running master branch on a vanilla Ubuntu 18.04 install (not Docker-ized). Standard systemd unit file produces a 100% CPU utilization due to loop logic. Is this in pipeline to address, or is the best workaround to wrap in a screen -DmS shell?

[Unit]
Description=kms
After=network.target
Wants=network-online.target

[Service]
ExecStart=/usr/bin/python3 /opt/kms/py-kms/pykms_Server.py -V DEBUG --logfile /var/log/py-kms_server.log
Restart=always
KillMode=process
Type=idle
User=nobody
Group=nogroup

[Install]
WantedBy=multi-user.target

from py-kms.

Netzvamp avatar Netzvamp commented on August 21, 2024

I have the same issue and fixed it by reducing the load in the main busy-waiting loops.

Try this patch:

diff --git a/py-kms/pykms_Server.py b/py-kms/pykms_Server.py
index 80c182a..2a1638d 100644
--- a/py-kms/pykms_Server.py
+++ b/py-kms/pykms_Server.py
@@ -10,6 +10,7 @@ import logging
 import os
 import errno
 import threading
+import time

 try:
         # Python 2 import.
@@ -57,6 +58,7 @@ class server_thread(threading.Thread):
                                     self.is_running = False
                                     self.server = None
                             self.queue.task_done()
+                    time.sleep(0.1)

 ##-----------------------------------------------------------------------------------------------------------------------------------------------

@@ -249,6 +251,7 @@ class kmsServer(socketserver.BaseRequestHandler):
                                 loggersrv.info("Responded to activation request.")
                                 ShellMessage.Process([-3, 18, 19]).run()
                                 break
+                time.sleep(0.1)

         def finish(self):
                 self.request.close()

ZIP file:
pykms-reduce-cpu.zip

Valid fix, i guess.

from py-kms.

TCB13 avatar TCB13 commented on August 21, 2024

Also having this issue, the patch seems to work.

from py-kms.

SystemRage avatar SystemRage commented on August 21, 2024

Adding some timeout when getting from queue resolves cpu overload (similar to sleep(), but more elegant). The second timeout (in request handler) can be omitted, tested without it and cpu stays low.
So docker options -it or #51 could be not used.

from py-kms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.