Comments (7)
@revz79 Could you please provide any reproduce codes and which version you used?
By run examples/scheduler.py
and I see everything is OK even if I kill master manually when scheduler running.
from pymesos.
Hello,
Here is the scheduler, i've got it from the examples, removing the 'addict' module dependency:
import logging
import os
import signal
import socket
import sys
import threading
import typing
import time
import uuid
import pymesos
logging.basicConfig(level=logging.DEBUG)
TASK_CPU = 4
TASK_MEM = 32
EXECUTOR_CPUS = 0.1
EXECUTOR_MEM = 32
class TestScheduler(pymesos.Scheduler):
def __init__(self, executor: typing.Dict):
self._executor: typing.Dict = executor
def registered(self, driver, frameworkId, masterInfo):
logging.debug(
f'Registered (framework: {frameworkId}, master info: {masterInfo}).')
def resourceOffers(self, driver, offers):
filters = {'refuse_seconds': 5}
for offer in offers:
cpus = self.getResource(offer['resources'], 'cpus')
mem = self.getResource(offer['resources'], 'mem')
if cpus < TASK_CPU or mem < TASK_MEM:
continue
task_id = str(uuid.uuid4())
task = {
'task_id': {
'value': task_id
},
'agent_id': {
'value': offer['agent_id']['value']
},
'name': f'task {task_id}',
'executor': self._executor,
'data': pymesos.encode_data(f'Hello from task {task_id}!'.encode())
}
task['resources'] = [
{
'name': 'cpus',
'type': 'SCALAR',
'scalar': {'value': TASK_CPU}
},
{
'name': 'mem',
'type': 'SCALAR',
'scalar': {'value': TASK_MEM}
}
]
driver.launchTasks(offer['id'], [task], filters)
def getResource(self, res, name):
resource = list(filter(lambda x: x['name'] == name, res))[0]
return resource.get('scalar', {'value': 0.0}).get('value', 0.0)
def statusUpdate(self, driver, update):
logging.debug(
f'Status update TID {update["task_id"]["value"]} {update["state"]}')
def main(master):
executor = {
'executor_id': {
'value': str(uuid.uuid4())
},
'name': 'TestExecutor',
'command': {
'value': f'python3 /opt/python/executor.py'
},
'resources': [
{
'name': 'mem',
'type': 'SCALAR',
'scalar': {
'value': EXECUTOR_MEM
}
},
{
'name': 'cpus',
'type': 'SCALAR',
'scalar': {
'value': EXECUTOR_CPUS
}
}
]
}
driver = pymesos.MesosSchedulerDriver(
sched=TestScheduler(executor=executor),
framework={
'user': 'test_user',
'name': 'test_name'
},
master_uri=master
)
def signal_handler(signal, frame):
driver.stop()
def run_driver_thread():
driver.run()
driver_thread = threading.Thread(target=run_driver_thread, args=())
driver_thread.start()
logging.info('Scheduler running, Ctrl+C to quit.')
signal.signal(signal.SIGINT, signal_handler)
while driver_thread.is_alive():
time.sleep(1)
if __name__ == '__main__':
main(master='127.0.0.1:5050')
Here below is the executor code which doesn't launch the task:
import logging
import sys
import time
import threading
import typing
import pymesos
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.FileHandler('task.log'))
class TestExecutor(pymesos.Executor):
def registered(self, driver, executorInfo, frameworkInfo, slaveInfo):
LOG.debug(
f'Executor regitered (driver: {driver}, executorInfo: {executorInfo}, frameworkInfo: {frameworkInfo}, slaveInfo: {slaveInfo}).')
def launchTask(self, driver, task):
def run_task(task: typing.Dict):
update = {
'task_id': {
'value': task['task_id']['value'],
},
'state': 'TASK_RUNNING',
'timestmp': time.time(),
}
driver.sendStatusUpdate(update)
LOG.info(pymesos.decode_data(task['data']))
time.sleep(30)
update = {
'task_id': {
'value': task['task_id']['value'],
},
'state': 'TASK_FINISHED',
'timestmp': time.time(),
}
driver.sendStatusUpdate(update)
thread = threading.Thread(target=run_task, args=(task,))
thread.start()
if __name__ == '__main__':
driver = pymesos.MesosExecutorDriver(TestExecutor())
driver.run()
I added some logging and i saw that the the the script is launched by the agent (the if __name__ == '__main__':
branch is executed) but the launchTask metchod is never called.
Extending the pymesos.MesosExecutorDriver
class and overriding the start() method, solved the problem:
class TestMesosExecutorDriver(pymesos.MesosExecutorDriver):
def start(self):
super().start()
self._notify()
The executor code became:
if __name__ == '__main__':
driver = TestMesosExecutorDriver(TestExecutor())
driver.run()
I'm using the 0.35 release.
Thank you,
from pymesos.
@revz79 Still not reproduced use your codes in our test cluster, what's your python version? And if you want to fix it as soon, could you please provide an environment like this ?
from pymesos.
I've experienced the same issue using the example program. The "Process" class takes a 'master' argument, but assigns it to _new_master. _new_master is only transferred to _master via the _notify method as mentioned, which is called by 'change_master' when a new master is set. Either the MesosExecutorDriver code should a) call change_master by default like the MesosSchedulerDriver does in its 'start' function (as seems to be related to the discussion above) or b) save the 'master' argument to the Process argument in self._master so that the user can specify an initial master at startup if they want, or leave as None.
Change this
class Process(object):
def __init__(self, master=None, timeout=DAY):
self._master = None
...
self._new_master = master
...
to this
class Process(object):
def __init__(self, master=None, timeout=DAY):
self._master = master
...
self._new_master = master
...
from pymesos.
@revz79 @mattleaverton I guess PR: #111 solves this problem, plz look at it.
from pymesos.
Released: https://github.com/douban/pymesos/releases/tag/0.3.6
from pymesos.
Yes v0.3.6 fixes this issue for me - thank you.
from pymesos.
Related Issues (20)
- Using 'offer_id' instead of 'inverse_offer_id' in RescindInverseOffer
- MesosOperatorMasterDriver cannot subscribe to events HOT 7
- Missing comma in list.
- missing kazoo dependency HOT 5
- Exponential backoff for executors incompatible with default & max executor_reregistration_timeout HOT 1
- Add support for HTTPS HOT 2
- Add support for executor authentication HOT 1
- Add specific timeout for http requests HOT 3
- pymesos doesn't install on python 3.7 HOT 5
- Ability to run 10,000 tasks HOT 1
- Pymesos doesn't install properly on python3.11 due to http_parser
- python version, is python2 and python3 compatible? HOT 2
- Scheduler failover flag is unsettable HOT 13
- Socket errors are not handled properly which is resulting in unexpected behavior HOT 2
- how do i get status of a task from scheduler? HOT 3
- Custom field on update dictionary not working HOT 2
- Error parsing `mins` and `ns` time units since items()
- Framework does not get HeartBeats HOT 1
- Timeout for connection refused errors?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymesos.