David Hamelech’s Dedication(Masechet Berachot Daf ד. Perek 1 Siman 15)

(based on Berachot 1:15)

Gemara: “[A song of] David: guard my soul for I am pious” (Tehillim 86:2)… This is what David was saying before Hashem: ‘Master of the Universe, am I not pious, for all kings of east and west sleep until three hours into the morning and I at midnight I shall awake to praise you?’
Ein Ayah: One can ask: have we not established that one who works for pay for his friend and, all the more so, if he works for the public, is not allowed to afflict himself, lest he get sick and the work of the public will not get done. This concept is illustrated in the Sifra that says that a worker should not stay up late at night and is found in the poskim [see Shulchan Aruch, Choshen Mishpat 337:19]. If so, and since no one fits into the category of one who works for the public more than a king, how could David afflict himself with sleep deprivation to such an extent?
What we must say is that David’s love of Hashem was so strong in his heart that because of this love, his service of Hashem was considered to him as rest, and he did not feel any affliction. This is why David stressed that “I am pious” (chassid). He meant by that that he served Hashem through love. Kings of other countries slept longer hours so that they could have a clear heart and find comfort so that they could work effectively on behalf of their nation. However, David said that he would wake up at midnight and would nevertheless not feel tiredness as a result when serving the public, and all of this was due to the true love that he had.