Ask for recommendation letters four to six weeks ahead, with everything in one go
Ask at least four to six weeks ahead; in application season a professor may be writing several letters at once, so earlier is better.
When you ask, hand over everything at once: transcript, CV, SOP draft, the list of schools and deadlines, how each one collects the letter, and your own internal deadline. Cornell's Graduate School also suggests adding relevant coursework, paper titles with abstracts, and any awards. Choose the person who can describe something specific about you rather than the one with the biggest title; programmes mostly prefer academic letters, but many accept a work supervisor too, and internship managers and project leads are common choices. Being asked to draft the letter yourself is also common.
No professor to write a letter?
An internship manager, project lead or club advisor all work; what matters is that they can describe something specific. Being asked to draft it yourself is also common.