You can check in Sonar Preferences (under the Edit tab) to see what Sonar is reporting for your Total Round Trip Latency, and you can check in your ASIO drivers (accessed either through the ASIO Control Panel button in Preferences or for some drivers there is a separate icon to launch their driver control UI through a program that you find in the Windows System Tray area - which is at the bottom right corner of your Windows Task Bar).
Anyways, during recording/tracking, you need to have your ASIO Buffer Size set small enough to where you don't have noticeable delay when hitting notes. I happen to use an ASIO Buffer Size of 128 samples, which gives me a Total Round Trip Latency as reported by Sonar, of around 10 milliseconds. I COULD go with a smaller size, but at some point that could result in some glitches in the sound processing through the ASIO drivers, so I completely avoid that by settling on a 128 sample size - neither the computer nor the interface have to work too hard, and I cannot detect any delay when trying to record.
When I finish recording, and move on to mixing, there are different conditions - principally, there is no longer a concern about recording delay, because I am no longer recording. It is at THIS point in the workflow that I need/want a MUCH larger ASIO Buffer Size, because then I can load up the project with effects that by their very nature need a large buffer size to process the effects properly. (things like a convoluted reverb will typically be in this effect category, and other types of effects, such as linear phase types can also dictate the use of a large ASIO Buffer Size). SOOOO - when mixing, I always bump up my ASIO Buffer Size to either 1024 or 2048, depending on which audio interface I am using (some allow only up to 1024, while others allow up to 2048).
Another possibility is that while recording, you have one or more effects loaded into the project, that as noted above will introduce a large latency, by their very design/nature. An easy way to determine this is to see if your delay goes instantly away if you temporarily hit the letter 'E' on your computer keyboard and then try playing some notes. That letter 'E' is the Sonar shortcut key that will toggle On/Off the bypassing of all effects in the active project. IF the delay goes away when the effects are bypassed, then you KNOW that one or more of the loaded effects are causing this delay issue, and you can work through disabling one at a time til you find the culprit, etc.... You can turn effects processing back on if bypassed, simply by hitting the letter 'E' again - it simply toggles all loaded effects On or Off.
I hope the above helps,
Bob Bone