Local SGD with Periodic Averaging: Tighter Analysis and Adaptive Synchronization