简体   繁体   中英

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. 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?

I've thought of having the Windows Service doing the processing directly (which I'd ideally like), but this isn't an option. Would it be better to be using 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. 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. So the question I have is, would using another approach help speed this up, such as using WCF and a different protocol? 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). So using WCF is a good step if you don't want to introduce bigger changes into your application.

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. 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).

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, ...). 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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