Please ask early and not one week from deadline! The better I know you, the more compelling the letter: so it's preferable if you have done research with me for a while, or have taken my classes and participated actively. At the same time, don't be afraid to bring this up (I know I certainly was/am worried that I would bother my mentors), First, it doesn't hurt to ask, and second, we professors know that this is our job.