By the length of a finite system of generators for a finite-dimensional associative algebra over an arbitrary field one means the least positive integer k such that the words of length not exceeding k span this algebra (as a vector space). The maximum length for the systems of generators of an algebra is referred to as the length of the algebra. In the present paper, an upper bound for the length of a commutative algebra in terms of a function of two invariants of the algebra, the dimension and the maximal degree of the minimal polynomial for the elements of the algebra, is obtained. As a corollary, a formula for the length of the algebra of diagonal matrices over an arbitrary field is obtained.Bibliography: 8 titles.