Normal sleep can be divided into two parts: rapid eye movement or REM sleep and non-rapid eye movement or non-REM sleep-- which has 4 stages. Your sleep cycle starts with N1 (N2,N3,N4)and ends with REM sleep. The body goes through each cycle 5 to 6 times a night and each lasts 60 to 90 minutes. If you happen to awaken during the N3 sleep, then you will feel groggy. There is the belief that if you adjust your sleep time to include only 90-minute cycles for example: 6 hours of sleep versus 5 and a-half you have a better chance of not waking up groggy. This is not true at all. The important trick to awaken without feeling groggy is to get enough total sleep each and every night. For a normal adult this would be between 7-8 hours. How many of us are getting 7-8 hours of sleep each night?
And what if you can't fall asleep? If you awaken in the night for more than 20 minutes--get up! It is best to read a book, listen to relaxing music. Don't watch TV or get on your phone. Electronics are known to wreak havoc with your sleep. And what about that glass of warm milk? Milk is great because it contains tryptophan which can give you a sleepy feeling. No not the cure for sleepless nights, but it can help make you drowsy.
And as you might have guessed, there are plenty of Apps to help you set your sleep cycle and wake up at the right time. A good night's sleep may be just a google search away.