Canceling the cavity length induced phase noise in an optical ring cavity for phase shift measurement and spin squeezing