?
Solved

SQL CLR Slow at first start

Posted on 2010-09-02
3
Medium Priority
?
933 Views
Last Modified: 2012-05-10
When I execute and SQL CLR store procedure, the first time .... it is really slow and then faster the second time. Is there a way to maintain this fast without having to trigger the storeprocedure every 1 minute?
0
Comment
Question by:ismamicrosolutions
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Expert Comment

by:DBAduck - Ben Miller
ID: 33593447
The reason is because the CLR is Common Language Runtime and is hosted by SQL Server.  It still follows the model of CLR applications in that it is compiled down to IL (Intermediate Language) and in order to execute must use a process called JIT (Just in Time) compiling to get to bytecode or executable code.  This is done once at the beginning of the first execution and from then on uses the bytecode produced.  

So in any CLR or .NET language, you will incur the cost of the JIT on the first invocation.  This is what you are seeing.

Also note that this only happens when the AppDomain is recycled, which is governed by the CLR and I am not sure how often that happens in SQL.
0
 

Author Comment

by:ismamicrosolutions
ID: 33593467
But is there a way to bypass just in time or insert it as a more native language so no JIT need?
0
 
LVL 25

Accepted Solution

by:
DBAduck - Ben Miller earned 2000 total points
ID: 33593478
Not that I am aware of.  You will load the assembly with CREATE ASSEMBLY and in the validation it checks the MSIL.

So I am not aware of a way to create an assembly that has been NGEN'd to bytecode.  It will always JIT.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question