Search in sources :

Example 1 with ModelSaveRunningContext

use of com.tencent.angel.model.ModelSaveRunningContext in project angel by Tencent.

the class AMModelSaver method serviceStart.

@Override
public void serviceStart() throws Exception {
    dispatcher = new Thread(new Runnable() {

        @Override
        public void run() {
            while (!stopped.get() && !Thread.interrupted()) {
                try {
                    lock.lock();
                    if (currentRequestId == -1 && waitingTasks.size() > 0) {
                        ModelSaveRunningContext runningContext = waitingTasks.remove(0);
                        save(runningContext);
                    }
                } finally {
                    lock.unlock();
                }
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                if (!stopped.get()) {
                    LOG.error("model save dispatcher is interrupt ", e);
                }
            }
        }
    });
    dispatcher.setName("model save dispatcher");
    dispatcher.start();
}
Also used : ModelSaveRunningContext(com.tencent.angel.model.ModelSaveRunningContext)

Example 2 with ModelSaveRunningContext

use of com.tencent.angel.model.ModelSaveRunningContext in project angel by Tencent.

the class AMModelSaver method save.

/**
 * Save model
 *
 * @param saveContext save model context
 * @return save request id
 */
public int save(ModelSaveContext saveContext, SaveTriggerMode triggerMode) {
    try {
        lock.lock();
        int requestId = saveRequestIdGen++;
        saveContext.setTmpSavePath(HdfsUtil.generateTmpDirectory(context.getConf(), context.getApplicationId().toString(), new Path(saveContext.getSavePath())).toString());
        // Path tmpPath = new Path(new Path(context.getConf().get(AngelConf.ANGEL_JOB_TMP_OUTPUT_PATH)),
        // String.valueOf(requestId));
        // Path tmpPath = HdfsUtil.toTmpPath(new Path(saveContext.getSavePath()));
        // saveContext.setTmpSavePath(tmpPath.toString());
        saveContexts.put(requestId, saveContext);
        results.put(requestId, new ModelSaveResult(requestId));
        results.get(requestId).setState(SaveState.INIT);
        boolean needAdd = true;
        // Filter old epoch trigger first
        if (triggerMode == SaveTriggerMode.EPOCH_TRIGGER) {
            int size = waitingTasks.size();
            for (int i = 0; i < size; i++) {
                if (waitingTasks.get(i).getTriggerMode() == SaveTriggerMode.EPOCH_TRIGGER) {
                    LOG.info("there is another epoch trigger model save request waiting, just exit");
                    needAdd = false;
                    break;
                }
            }
        }
        if (needAdd) {
            waitingTasks.add(new ModelSaveRunningContext(requestId, triggerMode, saveContext));
        }
        return requestId;
    } finally {
        lock.unlock();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ModelSaveRunningContext(com.tencent.angel.model.ModelSaveRunningContext) ModelSaveResult(com.tencent.angel.model.ModelSaveResult)

Aggregations

ModelSaveRunningContext (com.tencent.angel.model.ModelSaveRunningContext)2 ModelSaveResult (com.tencent.angel.model.ModelSaveResult)1 Path (org.apache.hadoop.fs.Path)1