I'm so sorry to hear about your furfriend. It is so hard to see them suffer. I had to make that decision last year with my 17 year old mini Poodle Indy. I still miss him something awful. But he was in so much pain I couldn't let him suffer anymore. You will know and your friend will let you know when it's time to let him go. He'll give you that look or just start withdrawing.
I hope you will be able to calm yourself and think rationally about your friend's needs. It's so hard, I know. I'll say a prayer for your breaking heart.