SNIReadSyncOverAsync and WaitForSingleObject blocking EF performance?

后端 未结 1 729
后悔当初
后悔当初 2020-12-29 23:12

I am doing some profiling on a WCF service that uses EF (System.Data.Entities) to read from a SQL DB. When I spin up multiple parallel clients that hit the serv

相关标签:
1条回答
  • 2020-12-29 23:39

    Are you able to distill this to a small code sample that reproduces the problem? What version of EF are you using?

    Here are a few observations based on the information you've given so far.

    EF Async

    Anything less than EF 6 is always synchronous. With EF 6 you have the option to use async methods instead. However, don't do this unless your WCF service also uses the async pattern.

    WCF Async

    You can write a WCF service whose implementation is asynchronous. See this documentation for more information.

    If you use one of the above methods, but not both, your code will not be asynchronous but will incur unnecessary synchronization overhead. Especially avoid Task.Run() or equivalents, since these will simply move work to another thread without actually improving throughput.

    Initialization

    Finally, another unrelated idea. Could your issue be related to EF initialization? When EF builds the metadata for a model it does this once per connection string. If multiple threads attempt to use the same model and that model has not yet been initialized, all threads will block until initialization is complete. To see if this is your issue, make one call to the service and allow it to complete. Then submit your 20 parallel requests. Do they still max out the CPU?

    0 讨论(0)
提交回复
热议问题