简体   繁体   English

从SQL CLR调用Web服务时潜在的性能问题

[英]Potential performance issues when calling web service from SQL CLR

I have a need to call external web service on certain events in my application. 我需要在应用程序中的某些事件上调用外部Web服务。 I don't want to modify my application and make any dependencies of that external web service. 我不想修改我的应用程序并使该外部Web服务具有任何依赖性。 So, I need to think of a way to do this with some sort of external component. 因此,我需要考虑一种使用某种外部组件进行此操作的方法。

One possible approach is that I make database view which will get filled up when some events in my application occurs. 一种可能的方法是使数据库视图在应用程序中发生某些事件时将被填充。 Then I will set up trigger on that view which will call CLR function. 然后,我将在该视图上设置触发器,该触发器将调用CLR函数。 In that CLR function I will make call to external web service. 在该CLR函数中,我将调用外部Web服务。 By doing this, I will get "real-time" integration which is good. 这样,我将获得很好的“实时”集成。 But, this approach has downsides. 但是,这种方法有缺点。 Major one is that it seems that calling web service from CLR is not a good idea since it will block main SQL thread (?!) until CLR receives some answer. 主要问题之一是从CLR调用Web服务似乎不是一个好主意,因为它将阻塞主SQL线程(?!),直到CLR收到一些答案为止。

Until now, I have only found that setting this property will help with performance issues: 到目前为止,我仅发现设置此属性将有助于解决性能问题:

System.Net.ServicePointManager.DefaultConnectionLimit = 9999

More about it you can find here . 您可以在这里找到更多关于它的信息

Now, since you know my needs (that is real-time or at least close-to-real-time integration without any calls from my application to exteranl web service) is there some better way to do it? 现在,既然您知道我的需求(即实时或至少接近实时的集成,而没有我的应用程序对外部Web服务的任何调用),那么有更好的方法吗?

One other approach I can think of is having some service which will periodically check for changes in my DB that needs to trigger calls to external web service. 我可以想到的另一种方法是拥有一些服务,该服务将定期检查数据库中是否需要触发对外部Web服务的调用的更改。 Once this service detects such change, it will call web service and transfer data. 一旦此服务检测到此类更改,它将调用Web服务并传输数据。 This is not true real-time integration of course. 当然,这不是真正的实时集成。 I must admit that, except for performance issues, I like having triggers and CLR much more since it guarantees real-time integration and has no affect on my application whatsoever. 我必须承认,除了性能问题外,我更喜欢触发器和CLR,因为它可以保证实时集成,并且对我的应用程序没有任何影响。

I am not sure that I would agree with the design of moving the web-service call to a database. 我不确定我是否同意将Web服务调用移至数据库的设计。 However, I am sure there are reasons as to why you wouldn't want to change the application. 但是,我肯定有您不希望更改应用程序的原因。

Here are a couple of options that you can try - 您可以尝试以下两种选择-

1) Instead of a database, and CLR making web-service calls, use a message queue. 1)使用消息队列来代替数据库和CLR进行Web服务调用。 NServiceBus is a good choice for passing event occurrences as message, which can trigger this call NServiceBus是将事件发生作为消息传递的不错选择,它可以触发此调用

2) If you are stuck with using SQL server to store the events, look at SQL server Service broker 2)如果您坚持使用SQL Server存储事件,请查看SQL Server Service Broker

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

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