-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug Fix] Fix bugs of time counter in gremlin service (#2906)
<!-- Thanks for your contribution! please review https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before opening an issue. --> ## What do these changes do? as titled <!-- Please give a short brief about these changes. --> ## Related issue number <!-- Are there any issues opened that will be resolved by merging this change? --> Fixes #2905 --------- Co-authored-by: Longbin Lai <[email protected]>
- Loading branch information
1 parent
6ade1d5
commit 7330954
Showing
12 changed files
with
253 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...engine/compiler/src/main/java/com/alibaba/graphscope/gremlin/plugin/MetricsCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2020 Alibaba Group Holding Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.graphscope.gremlin.plugin; | ||
|
||
import com.alibaba.graphscope.gremlin.Utils; | ||
import com.codahale.metrics.Timer; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
// collect metrics per gremlin query | ||
public class MetricsCollector { | ||
private final Timer.Context timeContext; | ||
private long startMillis; | ||
private long elapsedMillis; | ||
|
||
public MetricsCollector(Timer timer) { | ||
this.timeContext = timer.time(); | ||
} | ||
|
||
public long getStartMillis() { | ||
return this.startMillis; | ||
} | ||
|
||
public long getElapsedMillis() { | ||
return this.elapsedMillis; | ||
} | ||
|
||
public void stop() { | ||
this.startMillis = | ||
TimeUnit.NANOSECONDS.toMillis( | ||
Utils.getFieldValue(Timer.Context.class, timeContext, "startTime")); | ||
this.elapsedMillis = TimeUnit.NANOSECONDS.toMillis(timeContext.stop()); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...tive_engine/compiler/src/main/java/com/alibaba/graphscope/gremlin/plugin/QueryLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2020 Alibaba Group Holding Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.graphscope.gremlin.plugin; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class QueryLogger { | ||
private static final Logger defaultLogger = LoggerFactory.getLogger(QueryLogger.class); | ||
private static Logger metricLogger = LoggerFactory.getLogger("MetricLog"); | ||
|
||
private final String query; | ||
private final long queryId; | ||
|
||
public QueryLogger(String query, long queryId) { | ||
this.query = query; | ||
this.queryId = queryId; | ||
} | ||
|
||
public void info(String format, Object... args) { | ||
defaultLogger.info(this + " : " + format, args); | ||
} | ||
|
||
public void warn(String format, Object... args) { | ||
defaultLogger.warn(this + " : " + format, args); | ||
} | ||
|
||
public void error(String format, Object... args) { | ||
defaultLogger.error(this + " : " + format, args); | ||
} | ||
|
||
public void metricsInfo(String format, Object... args) { | ||
metricLogger.info(queryId + " | " + query + " | " + format, args); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + "query='" + query + '\'' + ", queryId=" + queryId + ']'; | ||
} | ||
|
||
public String getQuery() { | ||
return query; | ||
} | ||
|
||
public long getQueryId() { | ||
return queryId; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ine/compiler/src/main/java/com/alibaba/graphscope/gremlin/plugin/QueryStatusCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2020 Alibaba Group Holding Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.graphscope.gremlin.plugin; | ||
|
||
public class QueryStatusCallback { | ||
private final MetricsCollector metricsCollector; | ||
private final QueryLogger queryLogger; | ||
|
||
public QueryStatusCallback(MetricsCollector metricsCollector, QueryLogger queryLogger) { | ||
this.metricsCollector = metricsCollector; | ||
this.queryLogger = queryLogger; | ||
} | ||
|
||
public void onStart() {} | ||
|
||
public void onEnd(boolean isSucceed) { | ||
this.metricsCollector.stop(); | ||
queryLogger.info("total execution time is {} ms", metricsCollector.getElapsedMillis()); | ||
queryLogger.metricsInfo( | ||
"{} | {} | {}", | ||
isSucceed, | ||
metricsCollector.getElapsedMillis(), | ||
metricsCollector.getStartMillis()); | ||
} | ||
|
||
public QueryLogger getQueryLogger() { | ||
return queryLogger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Oops, something went wrong.