In this paper we study the problem of optimal controlling in a processor sharing (PS) M/M/2 queueing system with heterogeneous servers. The servers differ in the service intensities, operating and usage costs. The objective is to find the optimal policy to allocate the customers either to an idle or partially loaded server, or to the queue at each arrival and service completion epoch to minimize the long-run average cost per unit of time. We handle this optimization problem as Markov decision problem and study numerically structural properties of the optimal control policy. Using a policy-iteration algorithm we show that this policy for the current model is of threshold type. In this case the faster server handles customers with maximum capacity, while the number of simultaneously serviced customers at the slower server can be increased only when the number of waiting customers exceeds a certain threshold level. The data-sets generated by classic methodology of analyzing the controlled queues are used to explore predictions for optimal thresholds through artificial neural networks. The presented theoretical results are accompanied by heuristic solution and numerical examples. © 2020, Springer Nature Switzerland AG.