I have been struggling with similar problems and I haven't found any solution yet.
And I haven't got 500 users yet.
I have tried speeding up the script by changing from perl to php, I have also removed some things from it to get i faster.
After that a splitted the database, that made it faster until it gets too many users (150-200).
Then realised that the company running my server probably could have configured my mysql server better. We are still working on that.
Any input on how to configure things would be appreciated.
I get a feeling that the script in some way opens to many connections? I am not a programmer so I am not sure but could it be something not optimized in the way the script talks with the database?
Should one run with persistant connections or not, I have heard persistant connections could kill a server.