Solved

SQL CLR Slow at first start

Posted on 2010-09-02
3
918 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
  • 2
3 Comments
 
LVL 24

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 24

Accepted Solution

by:
DBAduck - Ben Miller earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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