I'm betting on a placebo effect of the melatonin. taken in pill form it is only effective for a few hours.
I've struggled with insomnia my whole life. If I'm able to fall asleep in the first place, I'm usually able to stay asleep long enough to get rested.
I only need the effect for about an hour, maybe 90 minutes. Long enough to fall asleep.