Bought a new pc and Minecraft gets lag every 2 seconds

I bought a new PC with 32gigs of ram and an i7 and a "decent" gpu. Me and my friends have a realms server and blablabla. Anyway, my game lags every 2 seconds for 1 millasecond. It's not really a problem, more of a nuisance. I've gotten Optifine and I've played with all of my settings and I get around (Without Optifine) 130-150 and with Optifine I get around 200, so my pc can easily handle it.

Buy a new computer

This isn't a problem with hardware it, it's the internet strength or connection.

Do you use Wi-Fi? If so did it come with the PC or did you use your own Wi-Fi adaptor/card you know works well?
Do you have a strong connection to the server?
Have you played Minecraft with your internet before this computer?

If you have a weak Wi-Fi adaptor it is going to lag, I recommend getting an internal Wi-Fi card if you use an adaptor, those suck for gaming. I highly recommend using a CAT Cable.