Skip to content

Commit 3c6cc3b

Browse files
committed
Merge branch 'feature-2.1.5' of https://github.com/FederatedAI/FATE-Serving into feature-2.1.5
2 parents cb2d068 + 61e98c6 commit 3c6cc3b

File tree

18 files changed

+137
-170
lines changed

18 files changed

+137
-170
lines changed

fate-serving-admin/src/main/java/com/webank/ai/fate/serving/admin/services/ComponentService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ public String getProject(String host, int port) {
8888
}
8989
return false;
9090
}).map(Map.Entry::getKey).findFirst();
91-
92-
return project.get();
91+
if(project.isPresent())
92+
return project.get();
93+
else
94+
return "";
9395
}
9496

9597
public boolean isAllowAccess(String host, int port) {

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/flow/FileMetricReport.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616

1717
package com.webank.ai.fate.serving.common.flow;
1818

19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
1922
import java.util.List;
2023

2124
public class FileMetricReport implements MetricReport {
2225

23-
private static final long DEFAULT_FILE_SIZE = 1024 * 1024;
26+
private static final long DEFAULT_FILE_SIZE = 1048576L;
2427

2528
MetricWriter metricWriter;
2629

30+
Logger logger = LoggerFactory.getLogger(FileMetricReport.class);
31+
2732
public FileMetricReport(String appName) {
2833
this.metricWriter = new MetricWriter(appName, DEFAULT_FILE_SIZE);
2934
}
@@ -37,7 +42,8 @@ public void report(List<MetricNode> data) {
3742
try {
3843
metricWriter.write(TimeUtil.currentTimeMillis(), data);
3944
} catch (Exception e) {
40-
e.printStackTrace();
45+
logger.error("metric writer error",e);
46+
4147
}
4248
}
4349
}

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/flow/FlowCounterManager.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,7 @@ public FlowCounterManager(String appName, Boolean countModelRequest) {
7878
}
7979
}
8080

81-
public static void main(String[] args) throws IOException {
82-
MetaInfo.PROPERTY_ROOT_PATH = new File("").getCanonicalPath();
83-
84-
FlowCounterManager flowCounterManager = new FlowCounterManager("test");
85-
flowCounterManager.setMetricReport(new FileMetricReport("Test"));
86-
flowCounterManager.setMetricSearcher(new MetricSearcher(MetricWriter.METRIC_BASE_DIR, "Test" + "-metrics.log.pid" + GetSystemInfo.getPid()));
87-
flowCounterManager.startReport();
88-
flowCounterManager.file = new File(MetaInfo.PROPERTY_ROOT_PATH + File.separator + ".fate" + File.separator + "flowRules.json");
89-
flowCounterManager.initialize();
90-
91-
int i = 0;
92-
while (true) {
93-
flowCounterManager.setAllowQps("source-" + i, i);
94-
i++;
95-
try {
96-
Thread.sleep(5000);
97-
} catch (InterruptedException e) {
98-
e.printStackTrace();
99-
}
100-
}
101-
/*while (true) {
102-
flowCounterManager.pass("M_test");
103-
try {
104-
Thread.sleep(100);
105-
} catch (InterruptedException e) {
106-
e.printStackTrace();
107-
}
108-
}*/
109-
}
81+
11082

11183
public MetricSearcher getMetricSearcher() {
11284
return metricSearcher;

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/flow/JvmInfoCounter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,5 @@ public void run() {
6868
}
6969
}
7070

71-
public static void main(String[] args) {
72-
JvmInfoCounter.start();
73-
while (true) {
74-
System.err.println(JvmInfoCounter.getMemInfos());
75-
try {
76-
Thread.sleep(1000);
77-
} catch (InterruptedException e) {
78-
e.printStackTrace();
79-
}
80-
}
81-
}
8271

8372
}

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/flow/MetricSearcher.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ private boolean validPosition(long beginTimeMs) {
151151
try {
152152
in = new FileInputStream(lastPosition.indexFileName);
153153
in.getChannel().position(lastPosition.offsetInIndex);
154+
154155
DataInputStream indexIn = new DataInputStream(in);
155-
// timestamp(second) in the specific position == that we cached
156-
return indexIn.readLong() == lastPosition.second;
156+
try { // timestamp(second) in the specific position == that we cached
157+
return indexIn.readLong() == lastPosition.second;
158+
}finally {
159+
indexIn.close();
160+
}
157161
} catch (Exception e) {
158162
return false;
159163
} finally {
@@ -175,10 +179,12 @@ private long findOffset(long beginTime, String metricFileName,
175179
}
176180
long beginSecond = beginTime / 1000;
177181
FileInputStream in = new FileInputStream(idxFileName);
182+
178183
in.getChannel().position(offsetInIndex);
179184
DataInputStream indexIn = new DataInputStream(in);
180-
long offset;
181185
try {
186+
long offset;
187+
182188
long second;
183189
lastPosition.offsetInIndex = in.getChannel().position();
184190
while ((second = indexIn.readLong()) < beginSecond) {
@@ -193,7 +199,12 @@ private long findOffset(long beginTime, String metricFileName,
193199
} catch (EOFException ignore) {
194200
return -1;
195201
} finally {
196-
indexIn.close();
202+
try {
203+
in.close();
204+
indexIn.close();
205+
}catch(Exception igore){
206+
207+
}
197208
}
198209
}
199210

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/flow/MetricsReader.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ boolean readMetricsInOneFileByEndTime(List<MetricNode> list, String fileName, lo
4747
FileInputStream in = null;
4848
long beginSecond = beginTimeMs / 1000;
4949
long endSecond = endTimeMs / 1000;
50+
BufferedReader reader = null;
5051
try {
5152
in = new FileInputStream(fileName);
5253
in.getChannel().position(offset);
53-
BufferedReader reader = new BufferedReader(new InputStreamReader(in, charset));
54+
reader = new BufferedReader(new InputStreamReader(in, charset));
5455
String line;
5556
while ((line = reader.readLine()) != null) {
5657
MetricNode node = MetricNode.fromFatString(line);
@@ -74,8 +75,15 @@ boolean readMetricsInOneFileByEndTime(List<MetricNode> list, String fileName, lo
7475
}
7576
}
7677
} finally {
77-
if (in != null) {
78-
in.close();
78+
try {
79+
if (in != null) {
80+
in.close();
81+
}
82+
if(reader!=null){
83+
reader.close();
84+
}
85+
}catch (Exception igore){
86+
7987
}
8088
}
8189
return true;
@@ -91,10 +99,11 @@ void readMetricsInOneFile(List<MetricNode> list, String fileName,
9199
lastSecond = list.get(list.size() - 1).getTimestamp() / 1000;
92100
}
93101
FileInputStream in = null;
102+
BufferedReader reader = null;
94103
try {
95104
in = new FileInputStream(fileName);
96105
in.getChannel().position(offset);
97-
BufferedReader reader = new BufferedReader(new InputStreamReader(in, charset));
106+
reader = new BufferedReader(new InputStreamReader(in, charset));
98107
String line;
99108
while ((line = reader.readLine()) != null) {
100109
MetricNode node = MetricNode.fromFatString(line);
@@ -110,8 +119,15 @@ void readMetricsInOneFile(List<MetricNode> list, String fileName,
110119
lastSecond = currentSecond;
111120
}
112121
} finally {
113-
if (in != null) {
114-
in.close();
122+
try {
123+
if (in != null) {
124+
in.close();
125+
}
126+
if (reader != null) {
127+
reader.close();
128+
}
129+
}catch(Exception igore){
130+
115131
}
116132
}
117133
}

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/model/Model.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,15 @@ public int hashCode() {
161161

162162
@Override
163163
public boolean equals(Object obj) {
164-
Model model = (Model) obj;
165-
return this.namespace.equals(model.namespace) && this.tableName.equals(model.tableName);
164+
if(obj!=null&&obj instanceof Model) {
165+
Model model = (Model) obj;
166+
if(this.namespace!=null&&this.namespace!=null)
167+
return this.namespace.equals(model.namespace) && this.tableName.equals(model.tableName);
168+
else
169+
return false;
170+
}else {
171+
return false;
172+
}
166173
}
167174

168175
@Override

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/utils/JVMGCUtils.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,5 @@ static public long getFullGCCollectionTime() {
8888
return fullGC == null ? 0 : fullGC.getCollectionTime();
8989
}
9090

91-
public static void main(String[] args) {
92-
List<List<Long>> listRoot = new ArrayList<List<Long>>();
93-
for (; ; ) {
94-
// System.out.println("=======================================================================");
95-
// System.out.println("getYoungGCName: " + JVMGCUtils.getYoungGCName());
96-
// System.out.println("getYoungGCCollectionCount: " + JVMGCUtils.getYoungGCCollectionCount());
97-
// System.out.println("getYoungGCCollectionTime: " + JVMGCUtils.getYoungGCCollectionTime());
98-
// System.out.println("getFullGCName: " + JVMGCUtils.getFullGCName());
99-
// System.out.println("getFullGCCollectionCount: " + JVMGCUtils.getFullGCCollectionCount());
100-
// System.out.println("getFullGCCollectionTime: " + JVMGCUtils.getFullGCCollectionTime());
101-
List<Long> list = new ArrayList<Long>(1000);
102-
listRoot.add(list);
103-
try {
104-
Thread.sleep(3000);
105-
} catch (InterruptedException e) {
106-
e.printStackTrace();
107-
}
108-
if (list.size() > 1) {
109-
list.remove(0);
110-
}
111-
Runtime.getRuntime().gc();
112-
}
113-
}
91+
11492
}

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/utils/JVMMemoryUtils.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -281,34 +281,5 @@ static private JVMMemoryUsage getAndResetMemoryPoolPeakUsage(MemoryPoolMXBean me
281281
return null;
282282
}
283283

284-
public static void main(String[] args) {
285-
List<List<Long>> listRoot = new ArrayList<List<Long>>();
286-
for(;;) {
287-
// System.out.println("=======================================================================");
288-
// System.out.println("getHeapMemoryUsage: " + JVMMemoryUtils.getHeapMemoryUsage());
289-
// System.out.println("getNonHeapMemoryUsage: " + JVMMemoryUtils.getNonHeapMemoryUsage());
290-
// System.out.println("getEdenSpaceMemoryUsage: " + JVMMemoryUtils.getEdenSpaceMemoryUsage());
291-
// System.out.println("getAndResetEdenSpaceMemoryPeakUsage: " + JVMMemoryUtils.getAndResetEdenSpaceMemoryPeakUsage());
292-
// System.out.println("getSurvivorSpaceMemoryUsage: " + JVMMemoryUtils.getSurvivorSpaceMemoryUsage());
293-
// System.out.println("getAndResetSurvivorSpaceMemoryPeakUsage: " + JVMMemoryUtils.getAndResetSurvivorSpaceMemoryPeakUsage());
294-
// System.out.println("getOldGenMemoryUsage: " + JVMMemoryUtils.getOldGenMemoryUsage());
295-
// System.out.println("getAndResetOldGenMemoryPeakUsage: " + JVMMemoryUtils.getAndResetOldGenMemoryPeakUsage());
296-
// System.out.println("getPermGenMemoryUsage: " + JVMMemoryUtils.getPermGenMemoryUsage());
297-
// System.out.println("getAndResetPermGenMemoryPeakUsage: " + JVMMemoryUtils.getAndResetPermGenMemoryPeakUsage());
298-
// System.out.println("getCodeCacheMemoryUsage: " + JVMMemoryUtils.getCodeCacheMemoryUsage());
299-
// System.out.println("getAndResetCodeCacheMemoryPeakUsage: " + JVMMemoryUtils.getAndResetCodeCacheMemoryPeakUsage());
300-
List<Long> list = new ArrayList<Long>(10000);
301-
listRoot.add(list);
302-
try {
303-
Thread.sleep(3000);
304-
} catch (InterruptedException e) {
305-
e.printStackTrace();
306-
}
307-
308-
if(list.size() > 1) {
309-
list.remove(0);
310-
}
311-
Runtime.getRuntime().gc();
312-
}
313-
}
284+
314285
}

fate-serving-common/src/main/java/com/webank/ai/fate/serving/common/utils/JVMThreadUtils.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,6 @@ static public int getDeadLockedThreadCount() {
9191
}
9292
}
9393

94-
public static void main(String[] args) {
95-
for (; ; ) {
96-
// System.out.println("=======================================================================");
97-
// System.out.println("getDaemonThreadCount: " + JVMThreadUtils.getDaemonThreadCount());
98-
// System.out.println("getNonHeapMemoryUsage: " + JVMThreadUtils.getThreadCount());
99-
// System.out.println("getPeakThreadCountAndReset: " + JVMThreadUtils.getAndResetPeakThreadCount());
100-
// System.out.println("getDeadLockedThreadCount: " + JVMThreadUtils.getDeadLockedThreadCount());
101-
try {
102-
Thread.sleep(5000);
103-
} catch (InterruptedException e) {
104-
e.printStackTrace();
105-
}
106-
}
107-
}
94+
10895
}
10996

0 commit comments

Comments
 (0)