Diversity helps ecosystems cope with stress