我有以下REST控制器接收二进制数据,使用AVRO解码器对其进行解码并执行一些返回字符串的操作
@RestController
public class MyRestController {
GenericDatumReader reader;
private static final Logger logger = LoggerFactory.getLogger(MyRestController.class);
public MyRestController() throws IOException {
String fullSchema = new String(Files.readAllBytes(Paths.get("full.avsc")), StandardCharsets.UTF_8);
String readerSchema = new String(Files.readAllBytes(Paths.get("reader.avsc")), StandardCharsets.UTF_8);
reader = new GenericDatumReader(new Schema.Parser().parse(fullSchema));
reader.setExpected((new Schema.Parser().parse(readerSchema)));
}
@RequestMapping(method = RequestMethod.POST,
value = "/calculate")
public String calculate( HttpServletRequest requestEntity) throws IOException {
long init = System.currentTimeMillis();
BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(IOUtils.toByteArray(requestEntity.getInputStream()), null);
String input = reader.read(null, decoder).toString();
String output = doSomeProcess(input);
long end = System.currentTimeMillis();
logger.info("time: " + (end- init));
return output;
}
}
正如您所看到的,我在返回输出之前在过程结束时打印毫秒。当我从运行REST服务的同一台机器上调用它时,它打印20毫秒,但是当我从本地机器(使用相同的二进制数据)进行调用时,它会打印大约200毫秒。我认为独立于我所称的地方,时间应该是相似的。结果似乎与多次测试一致,当我从笔记本电脑上调用它时,总是需要大约10倍。我有以下问题
MultipartFile
,但似乎要慢得多