简体   繁体   English

Windows服务将文件发送到Web Service瓶颈

[英]Windows service sending file to Web Service bottleneck

I have a windows service which monitors a directory and whenever it detects a new file it will send that file to my web service for processing. 我有一个监视目录的Windows服务,每当它检测到新文件时,它都会将该文件发送到我的Web服务进行处理。 I've now noticed that it's become a bit of a bottle neck sending the file using the web service request, so I was trying to work out what the alternatives are? 我现在已经注意到,使用Web服务请求发送文件变得有点瓶颈,所以我试图弄清楚替代方案是什么?

I've thought of having the Windows Service doing the processing directly (which I'd ideally like), but this isn't an option. 我曾想过让Windows服务直接进行处理(我理想情况下),但这不是一个选择。 Would it be better to be using WCF? 使用WCF会更好吗? In 90% of deployments the Web Service is on the same server as the Windows Service, but there is that 10% where it's on different servers. 在90%的部署中,Web Service与Windows服务位于同一服务器上,但有10%位于不同服务器上。 Just not sure what the best approach would be here... 只是不确定这里最好的方法是什么......

EDIT: I'm sending the file as a byte[] to the Web Service, this is what I am wanting to somehow speed up. 编辑:我将文件作为字节[]发送到Web服务,这是我想以某种方式加速。 So the question I have is, would using another approach help speed this up, such as using WCF and a different protocol? 所以我的问题是,使用其他方法有助于加快速度,例如使用WCF和不同的协议吗? I understand there is always an overhead, but trying to minimize this. 我知道总有一个开销,但试图尽量减少这个。

WCF & Bindings: Changing to WCF offers several bindings you can use that are more efficient to transmit data in a LAN, eg NetTcpBinding or Named Pipes (local only). WCF和绑定:更改为WCF提供了一些可以在LAN中传输数据更有效的绑定,例如NetTcpBinding或Named Pipes(仅限本地)。 So using WCF is a good step if you don't want to introduce bigger changes into your application. 因此,如果您不想在应用程序中引入更大的更改,那么使用WCF是一个很好的步骤。

Hybrid approach: However, the best way to speed up at least for the 90% of deployments that host both components on the same machine is to remove the process boundary in these cases. 混合方法:但是,至少对于在同一台计算机上托管两个组件的90%部署加速的最佳方法是在这些情况下删除进程边界。 As you mention, you've already thought about that. 如你所说,你已经考虑过了。 So just in case that the reason for putting the idea aside are the 10% of deployments that would require a distributed installation: By using an interface with an implementation for local procession and one for remote transmission, you could implement a configurable approach that supports both scenarios (90% very efficient, 10% at least not slower as before). 因此,如果放弃这个想法的原因是10%需要分布式安装的部署:通过使用具有本地处理实现的接口和用于远程传输的实现,您可以实现支持两者的可配置方法场景(90%非常高效,10%至少不像以前那样慢)。

Scaling down data sizes: Another - obvious - way to speed things up is to filter or compress the file contents before transmitting them to the service. 缩小数据大小:另一种显而易见的加速方法是在将文件内容传输到服务之前过滤或压缩文件内容。

File path instead of contents: As I understand your environment, the machines that host the services are at least close to each other (LAN, no firewall issues, ...). 文件路径而不是内容:据我了解您的环境,托管服务的计算机至少彼此接近(LAN,没有防火墙问题,......)。 So it might also be a viable option not to transmit the file contents to the service, but to notify the service of the file path and have the web service access the file directly. 因此,将文件内容传输到服务,但是通知服务文件路径并让Web服务直接访问文件也可能是一个可行的选择。 Though not a very beautiful way with certain downsides (eg account of web service must be able to access the file, path must also be accessible from the web service) you'd at least get rid of the inefficient transmission of the files and substitute that with a protocol that is built for file access. 虽然不是一个非常漂亮的方式,有某些缺点(例如,Web服务的帐户必须能够访问该文件,路径也必须可以从Web服务访问),您至少可以摆脱文件的低效传输并替换使用为文件访问而构建的协议。 Also in the 90% of installations where both services run on the same machine, the web service would do a local file access that should be very fast. 此外,在两个服务在同一台机器上运行的90%的安装中,Web服务将进行非常快速的本地文件访问。

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

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