We study the problem of online peak-demand minimization under energy storage
constraints. It is motivated by an increasingly popular scenario where
large-load customers utilize energy storage to reduce the peak procurement from
the grid, which accounts for up to 90% of their electric bills. The problem
is uniquely challenging due to (i) the coupling of online decisions across time
imposed by the inventory constraints and (ii) the noncumulative nature of the
peak procurement. In this paper, we develop an optimal online algorithm for the
problem, attaining the best possible competitive ratio (CR) among all
deterministic and randomized algorithms. We show that the optimal CR can be
computed in polynomial time, by solving a linear number of linear-fractional
problems. More importantly, we generalize our approach to develop an
\emph{anytime-optimal} online algorithm that achieves the best possible CR at
any epoch, given the inputs and online decisions so far. The algorithm retains
the optimal worst-case performance and achieves adaptive average-case
performance. Simulation results based on real-world traces show that, under
typical settings, our algorithms improve peak reduction by over 19% as
compared to baseline alternatives