Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of AvscSchemaWriter #537

Merged
merged 1 commit into from
Jan 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,27 @@ public void run() throws Exception {
throw new IllegalStateException("run() has already been invoked");
}

//"seal" any internal state to prevent plugins from trying to do weird things during execution
// "seal" any internal state to prevent plugins from trying to do weird things during execution
sealed = true;

int operationCount = operations.stream().collect(StreamUtil.toParallelStream(op -> {
try {
op.run(operationContext);
} catch (Exception e) {
throw new IllegalStateException("Exception running operation", e);
}
if (!operations.isEmpty()) {
long operationStart = System.currentTimeMillis();
final int parallelism = Math.min(operations.size(), 5);
karthikrg marked this conversation as resolved.
Show resolved Hide resolved
int operationCount = operations.stream().collect(StreamUtil.toParallelStream(op -> {
try {
op.run(operationContext);
} catch (Exception e) {
throw new IllegalStateException("Exception running operation", e);
}

return 1;
}, 2)).reduce(0, Integer::sum);
return 1;
}, parallelism)).reduce(0, Integer::sum);

LOGGER.info("Executed {} operations for builder plugins", operationCount);
long operationEnd = System.currentTimeMillis();
LOGGER.info("Executed {} operations with parallelism of {} for builder plugins in {} millis", operationCount,
parallelism, operationEnd - operationStart);
} else {
LOGGER.info("No operations specified to run");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,29 @@
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* generates java code from avsc files
*/
public class SchemaBuilder {

private static final Logger LOGGER = LoggerFactory.getLogger(SchemaBuilder.class);

private SchemaBuilder() { }

public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();

long pluginLoadStart = System.currentTimeMillis();
List<BuilderPlugin> plugins = loadPlugins(1);
long pluginLoadEnd = System.currentTimeMillis();
LOGGER.info("Loaded {} plugins in {} millis.", plugins.size(), pluginLoadEnd - pluginLoadStart);

long optionParseStart = System.currentTimeMillis();
karthikrg marked this conversation as resolved.
Show resolved Hide resolved
OptionParser parser = new OptionParser();

OptionSpec<String> inputOpt = parser.accepts("input", "Schema or directory of schemas to compile [REQUIRED]")
.withRequiredArg().required()
.describedAs("file");
Expand Down Expand Up @@ -253,7 +262,10 @@ public static void main(String[] args) throws Exception {
);

opConfig.validateParameters();
long optionParseEnd = System.currentTimeMillis();
LOGGER.info("Parsed all options in {} millis.", optionParseEnd - optionParseStart);

long operationContextBuildStart = System.currentTimeMillis();
OperationContextBuilder operationContextBuilder;
switch (opConfig.getGeneratorType()) {
case AVRO_UTIL:
Expand All @@ -267,6 +279,9 @@ public static void main(String[] args) throws Exception {
throw new IllegalStateException("unhandled: " + opConfig.getGeneratorType());
}
OperationContext opContext = operationContextBuilder.buildOperationContext(opConfig);
long operationContextBuildEnd = System.currentTimeMillis();
LOGGER.info("Built operation context in {} millis.", operationContextBuildStart - operationContextBuildEnd);

BuilderPluginContext context = new BuilderPluginContext(opContext);

// Allow other plugins to add operations
Expand All @@ -275,6 +290,9 @@ public static void main(String[] args) throws Exception {
}

context.run();

long end = System.currentTimeMillis();
LOGGER.info("Finished running SchemaBuilder in {} millis", end - start);
}

private static List<BuilderPlugin> loadPlugins(@SuppressWarnings("SameParameterValue") int currentApiVersion) {
Expand Down
Loading
Loading