WCF - Обрабатывание запроса от нескольких клиентов

Если вы хотите производительность массива 'C', но с дополнительной безопасностью и STL-подобной семантикой (итераторы, begin() и end() и т. Д.), Используйте boost::array .

По сути это шаблонная оболочка для 'C'-массивов с некоторыми NDEBUG -подключаемыми утверждениями проверки диапазона (а также с некоторыми std::range_error исключающими объектами).

Я использую такие вещи, как

boost::array,4> m;

вместо

float m[4][4];

все время, и это прекрасно работает (с соответствующими typedefs, чтобы в любом случае подавить многословие).


ОБНОВЛЕНИЕ: После некоторого обсуждения в комментариях здесь относительной производительности boost::array против boost::multi_array, я бы отметил, что этот код, скомпилированный с g++ -O3 -DNDEBUG на Debian / Lenny amd64 на Q9450 с 1333 МГц DDR3 RAM занимает 3,3 с для boost::multi_array против 0,6 с для boost::array.

#include 
#include 
#include "boost/array.hpp"
#include "boost/multi_array.hpp"

using namespace boost;

enum {N=1024};

typedef multi_array M;
typedef array,N>,N> C;

// Forward declare to avoid being optimised away
static void clear(M& m);
static void clear(C& c);

int main(int,char**)
{
  const clock_t t0=clock();

  {
    M m(extents[N][N][N]);
    clear(m);
  }

  const clock_t t1=clock();

  {
    std::auto_ptr c(new C);
    clear(*c);
  }

  const clock_t t2=clock();

  std::cout 
    << "multi_array: " << (t1-t0)/static_cast(CLOCKS_PER_SEC) << "s\n"
    << "array      : " << (t2-t1)/static_cast(CLOCKS_PER_SEC) << "s\n";

  return 0;
}

void clear(M& m)
{
  for (M::index i=0;i

5
задан iniki 9 October 2009 в 10:40
поделиться

1 ответ

In your default scenario, the WCF service host (the thing hosting your service class) will create a new instance of your service class for each request that comes in, and lets that handle the request ("per-call" activation).

You can tweak the maximum number of those concurrently active service class instances using the serviceThrottling behavior on your server.

<system.serviceModel>
   <behaviors>
      <serviceBehaviors>
         <behavior name="ThrottledServiceBehavior">
            <serviceThrottling 
                maxConcurrentCalls="25" 
                maxConcurrentSessions="25"
                maxConcurrentInstances="25"/>
         </behavior>
      </serviceBehaviors>
   </behaviors>

There's a really good explanation of the options of the service throttling behavior and its default values in Kenny Wolf's blog post here.

Also, setting of the InstanceContextMode and ConcurrencyMode on your service class (that implements the service contract) have a strong influence on how your service will handle concurrency and multiple requests.

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, 
                 ConcurrencyMode=ConcurrencyMode.Single)]
class YourServiceClass : IYourService
{
  .....
}

InstanceContextMode should be PerCall (each calling request gets a new, separate instance) and then ConcurrencyMode can be Single (which is the easiest to develop).

InstanceContextMode could also be PerSession if you need a session-based approach (not very common), or Single (your service class would a singleton - highly discouraged to use this, unless you absolutely, positively have to and know about all the quirks and problems with it!).

ConcurrencyMode could also be Reentrant (only relevant for duplex contracts and bindings) or Multiple (multithreaded singleton service class - highly risky and difficult to develop!).

Marc

11
ответ дан 13 December 2019 в 19:30
поделиться
Другие вопросы по тегам:

Похожие вопросы: