The device in the picture is a speed regulator for steam powered machines. As the machine ran, the top spins, as it spins the the steel balls are forced out by centrifugal force. That pushes down on on the center rod, that closed the valve letting steam into the machine. The speed of the machine could be adjusted by how far down the rod had to be pushed to close the valve. When the machine was spinning at top speed, the Balls were Out, hence full speed was said to be balls out. Nothing to do with male anatomy.
I am fascinated by steam operated machines. You can see how they work, all of the external parts moving back and forth, in and out, around and round. This example is in the machine room for Tower Bridge in London.