Commit 29fbb7fd authored by Chrysostomos Nanakos's avatar Chrysostomos Nanakos

deploy: Remove svipc module dependency

Update Gunicorn startup conf file.
parent 8637f8fe
......@@ -14,63 +14,108 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from pithos.workers import glue
import pickle
from svipc import sem_init, sem_take, sem_give
import os
from pithos.workers import glue
from multiprocessing import Lock
def find_hole(WORKERS, FOLLOW_WORKERS):
old_key = []
old_age = []
for key in FOLLOW_WORKERS:
if key not in WORKERS.keys():
old_age.append(FOLLOW_WORKERS[key] )
old_key.append( key )
break
if len(old_age) and len(old_key):
for key in old_key:
del FOLLOW_WORKERS[key]
return old_age
old_key = []
old_age = []
for key in FOLLOW_WORKERS:
if key not in WORKERS.keys():
old_age.append(FOLLOW_WORKERS[key])
old_key.append(key)
break
if len(old_age) and len(old_key):
for key in old_key:
del FOLLOW_WORKERS[key]
return old_age
return old_age
def follow_workers(pid, wid, WORKERS):
hole = None
try:
fd = open('/dev/shm/wid','rb')
f = pickle.load(fd)
hole = find_hole(WORKERS, f)
if len(hole) > 0:
k = {pid: int(hole[0])}
else:
k = {pid: wid}
f.update(k)
fd.close()
fd = open('/dev/shm/wid','wb')
pickle.dump(f, fd)
fd.close()
except:
fd = open('/dev/shm/wid','wb')
pickle.dump({pid:wid}, fd)
fd.close()
return hole
hole = None
if os.path.isfile('/dev/shm/wid'):
fd = open('/dev/shm/wid', 'rb')
f = pickle.load(fd)
hole = find_hole(WORKERS, f)
if len(hole) > 0:
k = {pid: int(hole[0])}
else:
k = {pid: wid}
f.update(k)
fd.close()
fd = open('/dev/shm/wid', 'wb')
pickle.dump(f, fd)
fd.close()
else:
fd = open('/dev/shm/wid', 'wb')
pickle.dump({pid: wid}, fd)
fd.close()
return hole
def allocate_wid(pid, wid, WORKERS):
d = {pid: wid}
hole = None
if sem_init(88,nums=1) == 0:
hole = follow_workers(pid, wid, WORKERS)
sem_give(88,0)
else:
sem_take(88,0)
hole = follow_workers(pid, wid, WORKERS)
sem_give(88,0)
return hole
hole = None
hole = follow_workers(pid, wid, WORKERS)
return hole
def post_fork(server,worker):
wid = allocate_wid(worker.pid,worker.worker_id, server.WORKERS)
if wid:
glue.WorkerGlue.setmap(worker.pid,wid[0])
else:
glue.WorkerGlue.setmap(worker.pid,worker.worker_id)
def when_ready(server):
server.lock = Lock()
def update_workers(pid, wid):
if os.path.isfile('/dev/shm/wid'):
fd = open('/dev/shm/wid', 'rb')
f = pickle.load(fd)
for k, v in f.items():
if wid == v:
del f[k]
break
k = {pid: wid}
f.update(k)
fd.close()
fd = open('/dev/shm/wid', 'wb')
pickle.dump(f, fd)
fd.close()
else:
fd = open('/dev/shm/wid', 'wb')
pickle.dump({pid: wid}, fd)
fd.close()
def resize_workers(no_workers):
if os.path.isfile('/dev/shm/wid'):
fd = open('/dev/shm/wid', 'rb')
f = pickle.load(fd)
for k, v in f.items():
if v > no_workers:
del f[k]
fd.close()
fd = open('/dev/shm/wid', 'wb')
pickle.dump(f, fd)
fd.close()
def post_fork(server, worker):
server.lock.acquire()
if worker.worker_id <= server.num_workers:
update_workers(worker.pid, worker.worker_id)
glue.WorkerGlue.setmap(worker.pid, worker.worker_id)
else:
wid = allocate_wid(worker.pid, worker.worker_id, server.WORKERS)
glue.WorkerGlue.setmap(worker.pid, wid[0])
resize_workers(server.num_workers)
server.lock.release()
def worker_exit(server, worker):
if glue.WorkerGlue.ioctx_pool:
glue.WorkerGlue.ioctx_pool._shutdown_pool()
def on_exit(server):
os.unlink('/dev/shm/wid')
......@@ -1708,9 +1708,7 @@ class Archip(base.Component):
class ArchipSynnefo(base.Component):
REQUIRED_PACKAGES = [
"python-svipc",
]
REQUIRED_PACKAGES = []
def _configure(self):
r1 = {"HOST": self.node.fqdn}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment