0

I am working on a program which logs memory usage on a server. The server has multiple instances running, and the program is logging all.

I am trying to figure out what would be more optimal.

Options:
(Assuming two instances)
1. Single Thread Program, which handles each instance, one by one. Time delay 0.5 seconds.
2. Double Thread, each handling one instance, Time Delay : 1 second.

Any suggestions?

Parag Gupta
  • 117
  • 1
  • 8

1 Answers1

2

Both options are perfectly fine. Note that writing a single-threaded program is way easier, so unless you have tight performance requirements or timing constraints, you should forgo threads in favor of faster development and less bugs.

phihag
  • 278,196
  • 72
  • 453
  • 469
  • Right now the priority is not fast-development, but better results, as the number of instances go upto 6-7 at times, and the log files do have some basic statistic calculations. – Parag Gupta Sep 16 '11 at 09:59
  • @Parag Gupta In Python, you'll have to watch out for the [GIL](http://stackoverflow.com/questions/1294382/what-is-a-global-interpreter-lock-gil) anyway (i.e. use `multiprocessing` instead of `threading` if your program is CPU-bound). Still, I'd always start with the simpler option. If you design your program carefully (for example, don't use global variables, have an independent method that measures a single instance once, etc.), you can still switch to multiple threads once it becomes necessary. – phihag Sep 16 '11 at 10:02
  • Thanks. I think I would go with a single thread in that case. If it becomes in-accurate later, would switch. =) – Parag Gupta Sep 16 '11 at 10:07