-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors and performance #28
Comments
Hello, thank you for posting an issue. Regarding the error messages: If you mind sharing the OS + OS version + chrome version of the machine you are running html2image on, I can check if I have the same error messages and if it seems to impact performances. Regarding performances, they are greatly affected by what you are screenshotting (and of course by the specs of the machine). Overall, there is not much room for optimization, because we are relying on Chrome for the image generation, but if you are generating a large amount of pictures, you may want to use some form of parallel processing. Parallel processing is not implemented in html2image (yet?), but you can add it to your own scripts if you wish to. Here is an example using a import time
import concurrent.futures
from html2image import Html2Image
HTML = """<h1> An interesting title </h1>"""
CSS = "body {background: red;}"
SCREENSHOT_COUNT = 100
hti = Html2Image(output_path='hti_parallel')
# Some class I have on my machine, don't know the source anymore
class Timer(object):
''' Timing Context Manager
'''
def __enter__(self):
self.start = time.perf_counter_ns()
return self
def __exit__(self, *args):
end = time.perf_counter_ns()
self.duration = (end - self.start) * 10**-9 # 1 nano-sec = 10^-9 sec
def test_classic():
results = [
hti.screenshot(
html_str=HTML,
# url='https://www.python.org',
css_str=CSS,
save_as=f'classic_{i}.png',
)
for i in range(SCREENSHOT_COUNT)
]
def test_TPE():
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
results = [
executor.submit(
hti.screenshot,
html_str=HTML,
# url='https://www.python.org',
css_str=CSS,
save_as=f'TPE_{i}.png',
)
for i in range(SCREENSHOT_COUNT)
]
if __name__ == '__main__':
print(f'Generating {SCREENSHOT_COUNT} images...')
with Timer() as t:
test_classic()
print(f'Classic generation took:\t {t.duration:.3f} \tseconds.')
with Timer() as t:
test_TPE()
print(f'Generation with ThreadPoolExecutor took:\t {t.duration:.3f} \tseconds.') When screenshotting a simple html string, it get the following output :
When screenshotting an url (by uncommenting the
In both cases, a significant performance improvement can be seen by using a ThreadPoolExecutor. |
Hi, thanks a lot for your detailed answer. I've done my test on OS X running on a MacBook pro. I'm screenshotting html code containing web animations in js. Each image generated is a step in the animation. I've redone the test using your sample code and the TPE took 28,5s for 100 images which is much better than the standard version. I still have these error messages: [0617/095441.400263:WARNING:ipc_message_attachment_set.cc(49)] MessageAttachmentSet destroyed with unconsumed attachments: 0/1 [0617/095441.503360:ERROR:command_buffer_proxy_impl.cc(123)] ContextResult::kTransientFailure: Failed to send GpuChannelMsg_CreateCommandBuffer. [0617/095440.775369:WARNING:headless_browser_main_parts.cc(106)] Cannot create Pref Service with no user data dir. |
Hello again. I recently ran html2image on a few different docker images based off on different OS and sometimes encountered messages like these. Using specific Chrome flags should theoretically make some of these warning disappear and solve the errors, but most of the time it didn't changed anything. I can't really do much about it as it is an "issue" directly related to Chrome / Chromium, the best would probably be to open a ticket bugs.chromium.org/ (or at least search for already existing ones). |
Hi, hti.screenshot is working fine for us even if we have concern regarding performance.
We have error messages during screenshots
Does theses errors have an impact on performance. Currently if takes 1,6s to generate a frame, and we would like to generate up to 100 (25img/s for 4s)
The text was updated successfully, but these errors were encountered: