Just as a follow-up given the effort to understand the scripts and ruby etc. and the likely performance, I went another route and bypassed all limits by writing directly to the database using SQL. This way I was able to get several thousand insertions per second.
There was a topic asking which tables were required, it is closed now so I reply here that I changed the following tables to insert the users: