The origin of this idiom . . . like many . . . isdebatable. However, the most widelyaccepted explanation is based in aviation. On airplanes, the throttle control handles . . . or joystick . . . and the fuel mixtureare often topped with grips that are ballshaped. When a pilot pushes the ballinto the full thrust position . . . towards the firewall . . . it pushes theaircraft to go as fast as possible.
On a side-note, if you've ever wondered why a joy stick iscalled thusly . . . well, chances are that is indeedy a vulgar term . . . theobvious implication that a (male) pilot was gripping the stick between hislegs; his joystick.
Another explanation involves steam engines. These engines have a mechanical regulatorthat utilize of a pair of hinged lever arms with a ball on the end of eacharm. As the engine speeds up, centrifugalforce causes the arms to rise up closing a valve. The regulator can be adjusted so that thearms go to horizontal (with the balls pointing to the wall) without closing thevalve. This adjustment does not limitthe speed of the engine so that it can go full force.
A similar explanation refers the automatic speed control fora diesel-generator . . . like those used on submarines. Inside the hydraulic governor roundcounterweights are attached to a vertical drive shaft. The weights (balls) areon hinged arms. As the engine spins, the drive shaft spins and slings the ballsoutward toward the walls of the governor housing. The faster the engine turns,the closer the balls get to the wall, i.e., engine at high speed, balls to thewall.