简体   繁体   English

dlang vibe.d RESTful服务性能

[英]dlang vibe.d RESTful Service Performance

Thank you for your assistance. 谢谢您的帮助。

Question: 题:
Why does my REST service seem to perform so poorly using rest interfaces in dlang vibe.d when compared to creating request handlers manually? 与手动创建请求处理程序相比,为什么在dlang vibe.d中使用rest接口时我的REST服务似乎表现不佳?

More Information: 更多信息:
I have been prototyping a RESTful service using the vibe.d library in dlang. 我一直在使用dlang中的vibe.d库对RESTful服务进行原型设计。 I'm running a test where a client sends GET and POST requests to the server with a payload of some given size, say 2048 byte (ie the GET response would have 2k, the POST request would have 2k). 我正在运行一个测试,其中客户端使用给定大小的有效负载(例如2048字节)将客户端发送GET和POST请求发送到服务器(即GET响应将为2k,POST请求将为2k)。

I'm using the " registerRestInterface " and " RestInterfaceClient " API in the vibe.d library to create my server and client sort of like this... 我正在vibe.d库中使用“ registerRestInterface ”和“ RestInterfaceClient ” API来创建我的服务器和客户端,就像这样...

Server: 服务器:

auto routes = new URLRouter;      

registerRestInterface(routes, new ArtifactArchive());

auto settings = new HTTPServerSettings();

settings.port = port;
settings.bindAddresses = [host];
settings.options |= HTTPServerOption.distribute;

listenHTTP(settings, routes);

runEventLoop();

Client: 客户:

IArtifactArchive archive = new RestInterfaceClient!IArtifactArchive(endpoint)  
IArtifactArchive.Payload result;  
result = archive.getContents(info.FileDescriptor, offset, info.BlockSize);

I'm not doing anything fancy in my interface. 我没有在界面中做任何花哨的事情。 Just filling a byte array and passing it along. 只需填充一个字节数组并将其传递。 I know performance depends on many different things; 我知道性能取决于许多不同的事物。 however I seem to see about 160kB transfer rate when using REST interfaces in vibe.d and roughly 5MB transfer rate when using manual http request handlers like this: 但是在vibe.d中使用REST接口时,我似乎看到约160kB的传输速率,而在使用手动http请求处理程序时,这样的传输率约为5MB:

void ManualHandleRequest(HTTPServerRequest req, HTTPServerResponse res) ...  
listenHTTP(settings, &ManualHandleRequest);

I really like the REST interface API, but I can't suffer that kind of performance loss in order to use it. 我真的很喜欢REST接口API,但是使用它不会造成那种性能损失。 Any thoughts on why it seems so much slower than the other method? 关于为什么它看起来比其他方法慢得多的想法? Perhaps I'm configuring something wrong or missing something. 也许我正在配置错误或缺少某些内容。 I am somewhat new to the D programming language and the vibe.d library. 我对D编程语言和vibe.d库有些陌生。

Thank you for your time! 感谢您的时间!

I suspect that with custom request handler you actually write response as a byte array. 我怀疑使用自定义请求处理程序实际上会将响应写为字节数组。 REST interface generator serializes all return data into JSON by default which creates huge overhead compared to raw array. REST接口生成器默认将所有返回数据序列化为JSON,与原始数组相比会产生巨大的开销。

This is just a random guess though, I need to see actual REST method implementation to say for sure and/or propose solution. 不过,这只是一个随机的猜测,我需要查看实际的REST方法实现以肯定地说和/或提出解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM