Bugfixes/improvements to scheduler

Move the PR#517 of apache-incubator-spark to the apache-spark