-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ranxianglei
authored and
ranxianglei.rxl
committed
Nov 13, 2024
1 parent
e1b3406
commit d48fff6
Showing
4 changed files
with
123 additions
and
3 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
18 changes: 18 additions & 0 deletions
18
paimon-format/src/main/resources/META-INF/services/org.apache.paimon.factories.Factory
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,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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. | ||
|
||
org.apache.paimon.format.avro.AvroFileFormatFactory | ||
org.apache.paimon.format.orc.OrcFileFormatFactory | ||
org.apache.paimon.format.parquet.ParquetFileFormatFactory |
101 changes: 101 additions & 0 deletions
101
paimon-format/src/test/java/org/apache/paimon/format/FormatPerformanceTest.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,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.paimon.format; | ||
|
||
import org.apache.paimon.factories.FactoryUtil; | ||
import org.apache.paimon.options.Options; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ServiceLoader; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** test format performance. */ | ||
public class FormatPerformanceTest { | ||
|
||
@Test | ||
public void testFormatPerformance() { | ||
double objectCacheCost = newFileFormatWithObjectCache(); | ||
double serviceCost = newFileFormatWithServiceLoader(); | ||
double factoryUtilCost = newFileFormatWithFactoryUtil(); | ||
assertThat(objectCacheCost * 30 < serviceCost).isTrue(); | ||
assertThat(objectCacheCost * 30 < factoryUtilCost).isTrue(); | ||
} | ||
|
||
private double newFileFormatWithServiceLoader() { | ||
for (int i = 0; i < 1000; i++) { | ||
loadFromIdentifier(); | ||
} | ||
int times = 10_000; | ||
long start = System.nanoTime(); | ||
int nothing = 0; | ||
for (int i = 0; i < times; i++) { | ||
nothing += loadFromIdentifier(); | ||
} | ||
nothing = 0; | ||
return ((double) (System.nanoTime() - start)) / 1000_000 / times + nothing; | ||
} | ||
|
||
private double newFileFormatWithObjectCache() { | ||
for (int i = 0; i < 1000; i++) { | ||
newFileFormat(); | ||
} | ||
int times = 10_000; | ||
long start = System.nanoTime(); | ||
for (int i = 0; i < times; i++) { | ||
newFileFormat(); | ||
} | ||
return ((double) (System.nanoTime() - start)) / 1000_000 / times; | ||
} | ||
|
||
private double newFileFormatWithFactoryUtil() { | ||
for (int i = 0; i < 1000; i++) { | ||
newFileFormatFromFactoryUtil(); | ||
} | ||
int times = 10_000; | ||
long start = System.nanoTime(); | ||
for (int i = 0; i < times; i++) { | ||
newFileFormatFromFactoryUtil(); | ||
} | ||
return ((double) (System.nanoTime() - start)) / 1000_000 / times; | ||
} | ||
|
||
private int loadFromIdentifier() { | ||
ServiceLoader<FileFormatFactory> serviceLoader = | ||
ServiceLoader.load(FileFormatFactory.class, FileFormat.class.getClassLoader()); | ||
int i = 0; | ||
for (FileFormatFactory factory : serviceLoader) { | ||
i++; | ||
} | ||
return i; | ||
} | ||
|
||
private FileFormat newFileFormat() { | ||
FileFormat orc = FileFormat.fromIdentifier("orc", new Options()); | ||
return orc; | ||
} | ||
|
||
@Test | ||
public void newFileFormatFromFactoryUtil() { | ||
FileFormatFactory fileFormatFactory = | ||
FactoryUtil.discoverFactory( | ||
FileFormatFactory.class.getClassLoader(), FileFormatFactory.class, "orc"); | ||
} | ||
} |
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