Getting rid of pent up sexual energy is what masturbation is for.
Here's the rule of thumb for married men who masturbate: as long as you still have enough left over for your wife you can masturbate all you want.
But, and this is a big but......As you grow older you may find yourself having difficulty with regular intercourse if you are a heavy masturbator. Add porn to the mix and the chances that you may actually come to prefer whacking off while watching porn to having sex with your wife may increase and this is a real danger. Don't ever masturbate when the wife is there, ready and willing.
If you ever start having problems getting or staying hard with your wife, or start having trouble ejaculating with her, that's a sign that you have to cut way back or even stop the masturbating and if you watch porn, get rid of it.