我正在使用java注释生成graphQL模式 . 感谢graphql-spqr library . 我正在调用代码
GraphQLSchemaGenerator schemaGenerator = new GraphQLSchemaGenerator()
.withResolverBuilders(new AnnotatedResolverBuilder())
.withValueMapperFactory(new JacksonValueMapperFactory())
.withOperationsFromSingleton(<annotatedClassObject>);
GraphQLSchema schema = schemaGenerator.generate();
每次调用graphQL API时都会执行上面的代码 . 我知道GraphQL Java库记录了以下行 .
/** Building this object is very cheap and can be done on each
* execution * if necessary. Building the schema is often not
* as cheap, especially if its parsed from graphql IDL schema
* format via {@link graphql.schema.idl.SchemaParser}.
*/
有什么方法可以收集生成此模式的每次调用需要多长时间的指标?
1 回答
我是graphql-spqr的作者 . 我可以告诉你的是,你肯定不应该为每一个请求都这个问题 . graphql-java文档引用的是
GraphQL
对象,构造起来确实很便宜,但架构不是 . SPQR在生成模式时扫描整个类层次结构,这在一般情况下相当昂贵 .你的用例到底是什么?为什么要在每次调用时构建一个新的模式实例?无论你想要实现什么 - 几乎可以肯定有更好的方法 .
至于测量时间,可以使用JMH(Java Microbenchmark Harness) .