Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Fix datastore performance issue #301

Merged
merged 5 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nni_manager/common/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface TrialJobInfo {
endTime?: number;
hyperParameters?: string[];
logPath?: string;
finalMetricData?: string;
finalMetricData?: MetricDataRecord;
stderrPath?: string;
}

Expand Down
22 changes: 14 additions & 8 deletions src/nni_manager/core/nniDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,23 @@ class NNIDataStore implements DataStore {
}

private async queryTrialJobs(status?: TrialJobStatus, trialJobId?: string): Promise<TrialJobInfo[]> {
const result: TrialJobInfo[]= [];
const result: TrialJobInfo[] = [];
const trialJobEvents: TrialJobEventRecord[] = await this.db.queryTrialJobEvent(trialJobId);
if (trialJobEvents === undefined) {
return result;
}
const map: Map<string, TrialJobInfo> = this.getTrialJobsByReplayEvents(trialJobEvents);

for (let key of map.keys()) {
const jobInfo = map.get(key);
const finalMetricsMap: Map<string, MetricDataRecord> = await this.getFinalMetricData(trialJobId);

for (const key of map.keys()) {
const jobInfo: TrialJobInfo | undefined = map.get(key);
if (jobInfo === undefined) {
continue;
}
if (!(status !== undefined && jobInfo.status !== status)) {
if (jobInfo.status === 'SUCCEEDED') {
jobInfo.finalMetricData = await this.getFinalMetricData(jobInfo.id);
jobInfo.finalMetricData = finalMetricsMap.get(jobInfo.id);
}
result.push(jobInfo);
}
Expand All @@ -179,16 +181,20 @@ class NNIDataStore implements DataStore {
return result;
}

private async getFinalMetricData(trialJobId: string): Promise<any> {
private async getFinalMetricData(trialJobId?: string): Promise<Map<string, MetricDataRecord>> {
const map: Map<string, MetricDataRecord> = new Map();
const metrics: MetricDataRecord[] = await this.getMetricData(trialJobId, 'FINAL');

const multiPhase: boolean = await this.isMultiPhase();

if (metrics.length > 1 && !multiPhase) {
this.log.error(`Found multiple FINAL results for trial job ${trialJobId}`);
for (const metric of metrics) {
if (map.has(metric.trialJobId) && !multiPhase) {
this.log.error(`Found multiple FINAL results for trial job ${trialJobId}`);
}
map.set(metric.trialJobId, metric);
}

return metrics[metrics.length - 1];
return map;
}

private async isMultiPhase(): Promise<boolean> {
Expand Down
18 changes: 16 additions & 2 deletions src/nni_manager/rest_server/test/mockedNNIManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,28 @@ export class MockedNNIManager extends Manager {
status: 'SUCCEEDED',
startTime: Date.now(),
endTime: Date.now(),
finalMetricData: 'lr: 0.01, val accuracy: 0.89, batch size: 256'
finalMetricData: {
timestamp: 0,
trialJobId: '3456',
parameterId: '123',
type: 'FINAL',
sequence: 0,
data: '0.2'
}
};
const job2: TrialJobInfo = {
id: '3456',
status: 'FAILED',
startTime: Date.now(),
endTime: Date.now(),
finalMetricData: ''
finalMetricData: {
timestamp: 0,
trialJobId: '3456',
parameterId: '123',
type: 'FINAL',
sequence: 0,
data: '0.2'
}
};

return Promise.resolve([job1, job2]);
Expand Down