Long time to load first sql connection in .NET

这一生的挚爱 提交于 2020-01-04 06:40:06

问题


For some reason it takes 7 seconds to open a connection to a sql server database for the firt time, subsequent connections takes a second. any idea what could be the reason?

I'm using C# and asp.net

Its after compilation, i essence every time i restart the site, which means every time it needs to actualy create the "first" connection. i understand that setting up connection pooling has overhead, but i have never seen that i should take 7 second to set it up.


回答1:


As well as connection pooling and CLR compilation, don't forget that the data and plan caches on the database server could be "cold" too...

I've seen first calls on a very "cold" web site take 5-10 seconds to respond from button click (for example, "search") to the data ending up on screen.




回答2:


The first time the connection has to be established which has a lot of overhead. Each subsequent connection is using connection pooling (assuming you have the same connection string) and the initial setup does not need to be done.

Edit: see this link or this one for some info on connection pooling.




回答3:


is this after a compile each time? Is the "lagtime" due to JIT compiling rather than the SqlConnection itself?



来源:https://stackoverflow.com/questions/2610821/long-time-to-load-first-sql-connection-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!