multiprocessing timestamp takes a lot of time
I created a program that spawn processes and run the provided algorithm. When I run the algorithm without multiprocessing it takes 1.7 sec, but when I spawn two processes that run the same algorithm it takes 18 sec.
Profiler result for one process without spawning:
68050 0.084 0.000 0.084 0.000 {method 'timestamp' of 'datetime.datetime' objects}
With spawning two processes for one of spawned processes:
34025 15.947 0.000 15.947 0.000 {method 'timestamp' of 'datetime.datetime' objects}
Why the date.timestamp takes 15.9 sec? Is this profiler error ?
Spawn:
# Start processes
for index, simulation in enumerate(self.simulations):
proc = Process(target=simulation_runner, args=(simulation, queues[index]))
jobs.append(proc)
proc.start()
Timestamp:
timestamp = math.floor(date.timestamp())
Also I wrote the program that do the same:
import time
from multiprocessing import Pool
from datetime import datetime
def worker(file_name):
with open(file_name, 'r+') as file:
for line in file:
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = ['FLT-TEST', 'FLT-TEST']
pool = Pool()
pool.map(worker, args)
# worker('FLT-TEST')
print(f'Executing in {time.time() - start} s.')
Without spawning it prints Executing in 0.16368794441223145 s.
With spawning it prints Executing in 66.31291604042053 s.
FLT-TEST
contains 91849 lines
Without file reading
import time
from multiprocessing import Pool
from datetime import datetime
def worker(num):
print(f'Process {num}')
for _ in range(95000):
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = [1, 2]
pool = Pool()
pool.map(worker, args)
# worker(1)
print(f'Executing in {time.time() - start} s.')
I get the same results.
python multiprocessing
add a comment |
I created a program that spawn processes and run the provided algorithm. When I run the algorithm without multiprocessing it takes 1.7 sec, but when I spawn two processes that run the same algorithm it takes 18 sec.
Profiler result for one process without spawning:
68050 0.084 0.000 0.084 0.000 {method 'timestamp' of 'datetime.datetime' objects}
With spawning two processes for one of spawned processes:
34025 15.947 0.000 15.947 0.000 {method 'timestamp' of 'datetime.datetime' objects}
Why the date.timestamp takes 15.9 sec? Is this profiler error ?
Spawn:
# Start processes
for index, simulation in enumerate(self.simulations):
proc = Process(target=simulation_runner, args=(simulation, queues[index]))
jobs.append(proc)
proc.start()
Timestamp:
timestamp = math.floor(date.timestamp())
Also I wrote the program that do the same:
import time
from multiprocessing import Pool
from datetime import datetime
def worker(file_name):
with open(file_name, 'r+') as file:
for line in file:
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = ['FLT-TEST', 'FLT-TEST']
pool = Pool()
pool.map(worker, args)
# worker('FLT-TEST')
print(f'Executing in {time.time() - start} s.')
Without spawning it prints Executing in 0.16368794441223145 s.
With spawning it prints Executing in 66.31291604042053 s.
FLT-TEST
contains 91849 lines
Without file reading
import time
from multiprocessing import Pool
from datetime import datetime
def worker(num):
print(f'Process {num}')
for _ in range(95000):
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = [1, 2]
pool = Pool()
pool.map(worker, args)
# worker(1)
print(f'Executing in {time.time() - start} s.')
I get the same results.
python multiprocessing
It's probably due to the processing involved of having the OS create and launch a separate task.multiprocessing
can involve a lot of overhead.
– martineau
Nov 21 '18 at 7:26
Comment: You should consider using atime.perf_counter()
for timing stuff like this.
– martineau
Nov 21 '18 at 7:31
add a comment |
I created a program that spawn processes and run the provided algorithm. When I run the algorithm without multiprocessing it takes 1.7 sec, but when I spawn two processes that run the same algorithm it takes 18 sec.
Profiler result for one process without spawning:
68050 0.084 0.000 0.084 0.000 {method 'timestamp' of 'datetime.datetime' objects}
With spawning two processes for one of spawned processes:
34025 15.947 0.000 15.947 0.000 {method 'timestamp' of 'datetime.datetime' objects}
Why the date.timestamp takes 15.9 sec? Is this profiler error ?
Spawn:
# Start processes
for index, simulation in enumerate(self.simulations):
proc = Process(target=simulation_runner, args=(simulation, queues[index]))
jobs.append(proc)
proc.start()
Timestamp:
timestamp = math.floor(date.timestamp())
Also I wrote the program that do the same:
import time
from multiprocessing import Pool
from datetime import datetime
def worker(file_name):
with open(file_name, 'r+') as file:
for line in file:
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = ['FLT-TEST', 'FLT-TEST']
pool = Pool()
pool.map(worker, args)
# worker('FLT-TEST')
print(f'Executing in {time.time() - start} s.')
Without spawning it prints Executing in 0.16368794441223145 s.
With spawning it prints Executing in 66.31291604042053 s.
FLT-TEST
contains 91849 lines
Without file reading
import time
from multiprocessing import Pool
from datetime import datetime
def worker(num):
print(f'Process {num}')
for _ in range(95000):
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = [1, 2]
pool = Pool()
pool.map(worker, args)
# worker(1)
print(f'Executing in {time.time() - start} s.')
I get the same results.
python multiprocessing
I created a program that spawn processes and run the provided algorithm. When I run the algorithm without multiprocessing it takes 1.7 sec, but when I spawn two processes that run the same algorithm it takes 18 sec.
Profiler result for one process without spawning:
68050 0.084 0.000 0.084 0.000 {method 'timestamp' of 'datetime.datetime' objects}
With spawning two processes for one of spawned processes:
34025 15.947 0.000 15.947 0.000 {method 'timestamp' of 'datetime.datetime' objects}
Why the date.timestamp takes 15.9 sec? Is this profiler error ?
Spawn:
# Start processes
for index, simulation in enumerate(self.simulations):
proc = Process(target=simulation_runner, args=(simulation, queues[index]))
jobs.append(proc)
proc.start()
Timestamp:
timestamp = math.floor(date.timestamp())
Also I wrote the program that do the same:
import time
from multiprocessing import Pool
from datetime import datetime
def worker(file_name):
with open(file_name, 'r+') as file:
for line in file:
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = ['FLT-TEST', 'FLT-TEST']
pool = Pool()
pool.map(worker, args)
# worker('FLT-TEST')
print(f'Executing in {time.time() - start} s.')
Without spawning it prints Executing in 0.16368794441223145 s.
With spawning it prints Executing in 66.31291604042053 s.
FLT-TEST
contains 91849 lines
Without file reading
import time
from multiprocessing import Pool
from datetime import datetime
def worker(num):
print(f'Process {num}')
for _ in range(95000):
date = datetime.now()
date.timestamp()
if __name__ == "__main__":
start = time.time()
args = [1, 2]
pool = Pool()
pool.map(worker, args)
# worker(1)
print(f'Executing in {time.time() - start} s.')
I get the same results.
python multiprocessing
python multiprocessing
edited Nov 21 '18 at 7:22
martineau
65.8k989177
65.8k989177
asked Nov 21 '18 at 6:41
Григорий Дикий
6610
6610
It's probably due to the processing involved of having the OS create and launch a separate task.multiprocessing
can involve a lot of overhead.
– martineau
Nov 21 '18 at 7:26
Comment: You should consider using atime.perf_counter()
for timing stuff like this.
– martineau
Nov 21 '18 at 7:31
add a comment |
It's probably due to the processing involved of having the OS create and launch a separate task.multiprocessing
can involve a lot of overhead.
– martineau
Nov 21 '18 at 7:26
Comment: You should consider using atime.perf_counter()
for timing stuff like this.
– martineau
Nov 21 '18 at 7:31
It's probably due to the processing involved of having the OS create and launch a separate task.
multiprocessing
can involve a lot of overhead.– martineau
Nov 21 '18 at 7:26
It's probably due to the processing involved of having the OS create and launch a separate task.
multiprocessing
can involve a lot of overhead.– martineau
Nov 21 '18 at 7:26
Comment: You should consider using a
time.perf_counter()
for timing stuff like this.– martineau
Nov 21 '18 at 7:31
Comment: You should consider using a
time.perf_counter()
for timing stuff like this.– martineau
Nov 21 '18 at 7:31
add a comment |
1 Answer
1
active
oldest
votes
timestamp = math.floor(date.replace(tzinfo=timezone.utc).timestamp())
Setting timezone fixed time duration.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406517%2fmultiprocessing-timestamp-takes-a-lot-of-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
timestamp = math.floor(date.replace(tzinfo=timezone.utc).timestamp())
Setting timezone fixed time duration.
add a comment |
timestamp = math.floor(date.replace(tzinfo=timezone.utc).timestamp())
Setting timezone fixed time duration.
add a comment |
timestamp = math.floor(date.replace(tzinfo=timezone.utc).timestamp())
Setting timezone fixed time duration.
timestamp = math.floor(date.replace(tzinfo=timezone.utc).timestamp())
Setting timezone fixed time duration.
answered Nov 21 '18 at 8:20
Григорий Дикий
6610
6610
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406517%2fmultiprocessing-timestamp-takes-a-lot-of-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's probably due to the processing involved of having the OS create and launch a separate task.
multiprocessing
can involve a lot of overhead.– martineau
Nov 21 '18 at 7:26
Comment: You should consider using a
time.perf_counter()
for timing stuff like this.– martineau
Nov 21 '18 at 7:31