Skip to content
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

Add SVG output option #10

Open
simonw opened this issue Oct 12, 2020 · 5 comments
Open

Add SVG output option #10

simonw opened this issue Oct 12, 2020 · 5 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented Oct 12, 2020

I have a hunch that this might perform better. Need to try it out to see.

@simonw
Copy link
Owner Author

simonw commented Oct 12, 2020

SVG version:

~ % ab -n 100 -c 1 'http://127.0.0.1:8009/penguins/penguins.seaborn?_seaborn=relplot'
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient).....done


Server Software:        uvicorn
Server Hostname:        127.0.0.1
Server Port:            8009

Document Path:          /penguins/penguins.seaborn?_seaborn=relplot
Document Length:        217486 bytes

Concurrency Level:      1
Time taken for tests:   49.957 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      21764600 bytes
HTML transferred:       21748600 bytes
Requests per second:    2.00 [#/sec] (mean)
Time per request:       499.565 [ms] (mean)
Time per request:       499.565 [ms] (mean, across all concurrent requests)
Transfer rate:          425.46 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   455  499  30.3    500     642
Waiting:      455  499  30.3    500     642
Total:        455  500  30.3    500     642

Percentage of the requests served within a certain time (ms)
  50%    500
  66%    514
  75%    516
  80%    520
  90%    533
  95%    553
  98%    569
  99%    642
 100%    642 (longest request)

PNG version:

~ % ab -n 100 -c 1 'http://127.0.0.1:8009/penguins/penguins.seaborn?_seaborn=relplot'
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient).....done


Server Software:        uvicorn
Server Hostname:        127.0.0.1
Server Port:            8009

Document Path:          /penguins/penguins.seaborn?_seaborn=relplot
Document Length:        42362 bytes

Concurrency Level:      1
Time taken for tests:   44.464 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4251800 bytes
HTML transferred:       4236200 bytes
Requests per second:    2.25 [#/sec] (mean)
Time per request:       444.641 [ms] (mean)
Time per request:       444.641 [ms] (mean, across all concurrent requests)
Transfer rate:          93.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   418  444  24.1    435     533
Waiting:      418  444  24.0    435     533
Total:        418  445  24.1    436     533

Percentage of the requests served within a certain time (ms)
  50%    436
  66%    442
  75%    466
  80%    472
  90%    478
  95%    484
  98%    525
  99%    533
 100%    533 (longest request)

@simonw
Copy link
Owner Author

simonw commented Oct 12, 2020

PNG performed a little better. But this is odd:

SVG = 217486 bytes
PNG = 42362 bytes

I don't think I believe that. Should dig further.

@simonw simonw changed the title Try using SVG instead of PNG for the output Add SVG output option Oct 12, 2020
@simonw
Copy link
Owner Author

simonw commented Oct 12, 2020

I'm going to add a ?_seaborn_output=svg option to opt-in to this.

@simonw
Copy link
Owner Author

simonw commented Dec 7, 2020

Here's my prototype:

+++ b/datasette_seaborn/__init__.py
@@ -35,15 +35,15 @@ def render_seaborn(columns, rows, request):
     method_fn = getattr(sns, method)
 
     figure = method_fn(data=df, **kwargs)
-    png = io.BytesIO()
+    image_bytes = io.BytesIO()
     if not hasattr(figure, "savefig"):
         figure = figure.get_figure()
-    figure.savefig(png, format="png")
+    figure.savefig(image_bytes, format="svg")
     if hasattr(figure, "clf"):
         figure.clf()
     else:
         figure.fig.clf()
-    return {"body": png.getvalue(), "content_type": "image/png"}
+    return {"body": image_bytes.getvalue(), "content_type": "image/svg+xml"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant