This completely puzzles me.
asset_hist = [] for key_host, val_hist_list in am_output.asset_history.items(): for index, hist_item in enumerate(val_hist_list): #row = collections.OrderedDict([("computer_name", key_host), ("id", index), ("hist_item", hist_item)]) row = {"computer_name": key_host, "id": index, "hist_item": hist_item} asset_hist.append(row)
This code works great with the commented collection line. However, when I comment out the row = dict line and delete the comment from the collection line, everything becomes very strange. There are about 4 million of these lines that are generated and added to asset_hist.
So, when I use row = dict, the whole cycle ends in about 10 milliseconds, lightning fast. When I use an ordered dictionary, I waited more than 10 minutes, and it still has not finished. Now I know that OrderDict should be a little slower than the recorder, but it should be about 10 times slower in the worst case, and in my math it's about 100,000 times slower in this function.
I decided to print the index in the bottom loop to see what happens. Interestingly, I noticed spraying at the console output. The index will print very quickly on the screen, and then stop for about 3-5 seconds before continuing.
am_output.asset_history is a dictionary that has one key, a host, and each line is a list of lines. For instance.
am_output.asset_history = {"host1": ["string1", "string2", ...], "host2": ["string1", "string2", ...], ...}
EDIT: Spray analysis using OrderedDict
Total memory on this VM server: only 8 GB ... you need to get more deactivation.
LOOP NUM
184796 (~ 5 seconds of waiting, ~ 60% of memory use)
634481 (~ 5 seconds of waiting, ~ 65% of memory use)
1197564 (~ 5 seconds of waiting, ~ 70% of memory use)
1899247 (~ 5 seconds of waiting, ~ 75% of memory use)
2777296 (~ 5 seconds of waiting, ~ 80% of memory use)
3873730 (LONG WAIT ... waited 20 minutes and gave up !, 88.3% of memory usage, the process is still running)
In the case where the wait occurs with each run.
EDIT : run it again, this time it will stop at 3873333, next to the place it stopped earlier. He stopped after forming a line, trying to add ... I did not notice this last attempt, but it was there too ... a problem with the added line, not the line of the line ... I'm still confused. Here's the line that she produced just before a long stop (she added a line to the print statement) ... the hostname was changed to protect the innocent:
3873333: OrderedDict ([('computer_name', 'bg-fd5612ea'), ('id', 1), ('hist_item', 'sys1 Normalizer (sys1-4): the domain name cannot be determined from sys1 Name' BG -fd5612ea '. ")])