use of com.tencent.angel.ps.ParameterServerId in project angel by Tencent.
the class AMModelSaver method save.
private void save(ModelSaveRunningContext runningContext) {
ModelSaveContext saveContext = runningContext.getSaveContext();
try {
lock.lock();
currentRequestId = runningContext.getRequestId();
LOG.info("Start to execute save request " + saveContext + " with request id=" + runningContext.getRequestId());
// Split the user request to sub-requests to pss
currentSubSaveContexts = split(currentRequestId, saveContext);
subResults = new HashMap<>(currentSubSaveContexts.size());
for (Map.Entry<ParameterServerId, PSMatricesSaveContext> entry : currentSubSaveContexts.entrySet()) {
subResults.put(entry.getKey(), new PSMatricesSaveResult(entry.getValue().getRequestId(), entry.getValue().getSubRequestId(), SaveState.INIT));
}
receivedSubResult = 0;
} finally {
lock.unlock();
}
}
use of com.tencent.angel.ps.ParameterServerId in project angel by Tencent.
the class AppStateStorage method writePSMeta.
/**
* write ps meta to file
*
* @param psManager ps meta storage
* @throws IOException
*/
public void writePSMeta(ParameterServerManager psManager) throws IOException {
try {
psMetaLock.lock();
// generate a temporary file
String psMetaFile = getPsMetaFile();
String tmpFile = getPSMetaTmpeFile(psMetaFile);
Path tmpPath = new Path(writeDir, tmpFile);
FSDataOutputStream outputStream = fs.create(tmpPath);
// write ps meta to the temporary file first.
Map<ParameterServerId, AMParameterServer> psMap = psManager.getParameterServerMap();
outputStream.writeInt(psMap.size());
PSAttemptId attemptId = null;
int nextAttemptIndex = 0;
for (Entry<ParameterServerId, AMParameterServer> entry : psMap.entrySet()) {
outputStream.writeInt(entry.getKey().getIndex());
attemptId = entry.getValue().getRunningAttemptId();
nextAttemptIndex = entry.getValue().getNextAttemptNumber();
if (attemptId != null) {
nextAttemptIndex = attemptId.getIndex();
}
outputStream.writeInt(nextAttemptIndex);
}
outputStream.close();
// rename the temporary file to the final file
Path psMetaFilePath = new Path(writeDir, psMetaFile);
HdfsUtil.rename(tmpPath, psMetaFilePath, fs);
// if the old final file exist, just remove it
if (lastPsMetaFilePath != null) {
fs.delete(lastPsMetaFilePath, false);
}
lastPsMetaFilePath = psMetaFilePath;
} finally {
psMetaLock.unlock();
}
}
use of com.tencent.angel.ps.ParameterServerId in project angel by Tencent.
the class AMModelSaver method split.
private Map<ParameterServerId, PSMatrixSaveContext> split(MatrixSaveContext matrixSaveContext) {
AMMatrixMetaManager matrixMetaManager = context.getMatrixMetaManager();
MatrixMeta meta = matrixMetaManager.getMatrix(matrixSaveContext.getMatrixName());
if (meta == null) {
throw new IllegalStateException("Can not find matrix " + matrixSaveContext.getMatrixName());
}
Map<Integer, PartitionMeta> partitions = meta.getPartitionMetas();
List<Integer> rowIndexes = matrixSaveContext.getRowIndexes();
Map<ParameterServerId, Set<Integer>> psIdToPartIdsMap = new HashMap<>();
if (rowIndexes == null || rowIndexes.isEmpty()) {
for (Map.Entry<Integer, PartitionMeta> partEntry : partitions.entrySet()) {
ParameterServerId psId = partEntry.getValue().getMasterPs();
if (psId == null) {
throw new IllegalStateException("Can not get ps for partition " + partEntry.getKey());
}
Set partIds = psIdToPartIdsMap.get(psId);
if (partIds == null) {
partIds = new HashSet();
psIdToPartIdsMap.put(psId, partIds);
}
partIds.add(partEntry.getKey());
}
} else {
int size = rowIndexes.size();
for (int i = 0; i < size; i++) {
for (Map.Entry<Integer, PartitionMeta> partEntry : partitions.entrySet()) {
if (!partEntry.getValue().contain(rowIndexes.get(i))) {
continue;
}
ParameterServerId psId = partEntry.getValue().getMasterPs();
if (psId == null) {
throw new IllegalStateException("Can not get ps for partition " + partEntry.getKey());
}
Set partIds = psIdToPartIdsMap.get(psId);
if (partIds == null) {
partIds = new HashSet();
psIdToPartIdsMap.put(psId, partIds);
}
partIds.add(partEntry.getKey());
}
}
}
int matrixId = meta.getId();
Map<ParameterServerId, PSMatrixSaveContext> ret = new HashMap<>(psIdToPartIdsMap.size());
for (Map.Entry<ParameterServerId, Set<Integer>> entry : psIdToPartIdsMap.entrySet()) {
List<Integer> partIds = new ArrayList<>(entry.getValue());
partIds.sort(new Comparator<Integer>() {
@Override
public int compare(Integer id1, Integer id2) {
return id1 - id2;
}
});
PSMatrixSaveContext psMatrixSaveContext = new PSMatrixSaveContext(matrixId, partIds, matrixSaveContext.getRowIndexes(), matrixSaveContext.getFormatClassName(), null, false, true);
ret.put(entry.getKey(), psMatrixSaveContext);
}
return ret;
}
use of com.tencent.angel.ps.ParameterServerId in project angel by Tencent.
the class AMMatrixMetaManager method assignPSForPartitions.
private void assignPSForPartitions(Partitioner partitioner, List<PartitionMeta> partitions) {
int partNum = partitions.size();
for (int i = 0; i < partNum; i++) {
int psIndex = partitioner.assignPartToServer(partitions.get(i).getPartId());
ParameterServerId psId = new ParameterServerId(psIndex);
partitions.get(i).addReplicationPS(psId);
partitions.get(i).makePsToMaster(psId);
}
}
use of com.tencent.angel.ps.ParameterServerId in project angel by Tencent.
the class AMMatrixMetaManager method buildPSMatrixMeta.
/**
* dispatch matrix partitions to parameter servers
*
* @param matrixMeta matrix meta proto
*/
private void buildPSMatrixMeta(MatrixMeta matrixMeta) {
Map<Integer, PartitionMeta> partMetas = matrixMeta.getPartitionMetas();
int matrixId = matrixMeta.getId();
Set<ParameterServerId> psIdSet = matrixIdToPSSetMap.get(matrixId);
if (psIdSet == null) {
psIdSet = new HashSet<>();
matrixIdToPSSetMap.put(matrixId, psIdSet);
}
for (Entry<Integer, PartitionMeta> partEntry : partMetas.entrySet()) {
List<ParameterServerId> psList = partEntry.getValue().getPss();
int size = psList.size();
for (int i = 0; i < size; i++) {
ParameterServerId psId = psList.get(i);
Map<Integer, MatrixMeta> psMatrixIdToMetaMap = matrixPartitionsOnPS.get(psId);
if (psMatrixIdToMetaMap == null) {
psMatrixIdToMetaMap = new HashMap<>();
matrixPartitionsOnPS.put(psId, psMatrixIdToMetaMap);
}
MatrixMeta psMatrixMeta = psMatrixIdToMetaMap.get(matrixId);
if (psMatrixMeta == null) {
psMatrixMeta = new MatrixMeta(partMetas.size(), matrixMeta.getMatrixContext());
psMatrixIdToMetaMap.put(matrixId, psMatrixMeta);
}
psMatrixMeta.addPartitionMeta(partEntry.getKey(), new PartitionMeta(partEntry.getValue().getPartitionKey(), new ArrayList<>(partEntry.getValue().getPss())));
psIdSet.add(psId);
}
}
// for(Entry<ParameterServerId, Map<Integer, MatrixMeta>> psEntry : matrixPartitionsOnPS.entrySet()) {
// LOG.info("ps id = " + psEntry.getKey());
// Map<Integer, MatrixMeta> matrixIdToMetaMap = psEntry.getValue();
// for(Entry<Integer, MatrixMeta> metaEntry : matrixIdToMetaMap.entrySet()) {
// LOG.info("matrix id = " + metaEntry.getKey());
// LOG.info("matrix partitons number = " + metaEntry.getValue().getPartitionMetas().size());
// }
// }
}
Aggregations