I have a script that would GREATLY benefit from being multi-threaded. The script basically looks up users in two systems, compares them, makes updates if needed, then logs it’s actions. Most of the time is used up doing the lookups. It would GREATLY benefit from being able to spin up several threads (asjobs I’m assuming).
Currently it takes 2.5 seconds per user to process. That’s fine for 500 or so users, but scaling it to 10,000 becomes ugly.
The first hurdle I need to figure out is how to handle logging. Currently the process does the lookups and the main function Returns at various points depending on the results it finds, and writes out an entry in 1-2 different CSV files. When I’m all done, I read in those files, cast them to HTML and send out a nice little report.
My problem is, I can’t figure out how to handle logging if I turn this into a multi-threaded process. I’m open to suggestions.
Without posting the entire set of code, here is the bases of how it works:
Reads in Userlist, dumps that userlist to the main function (big ol’ ugly foreach loop).
The main function writes to log 1, log 1 & 2, or just to log 3, depending on if users existed in both locations, if they needed updates, or if they were removed, etc. (out-file)
When done, I read in the 3 csv files, cast them to HTML then email out a report.
Any suggestions on how to keep logging straight and work correctly multi-threading this mess?