How to reach the optimal number of lactations in a dairy cow

Dairy cows usually achieve their maximum production at the 4th or 5th lactation. Many cows in modern dairy systems do not last that long, on average they are being culled after about 3 lactations. What is the optimal number of lactations for a dairy cow and how should farmers make correct culling decisions?