|
441 | 441 | "data_frame = GeoDataFrame.from_arrow(table)\n",
|
442 | 442 | "data_frame.plot()"
|
443 | 443 | ]
|
| 444 | + }, |
| 445 | + { |
| 446 | + "cell_type": "markdown", |
| 447 | + "id": "aff144a0", |
| 448 | + "metadata": {}, |
| 449 | + "source": [ |
| 450 | + "## Performance\n", |
| 451 | + "\n", |
| 452 | + "Let's do a small investigation into the performance characteristics of the two (partitioned, non-partitioned) datasets.\n", |
| 453 | + "We've uploaded them to the bucket `stac-fastapi-geoparquet-labs-375`, which is public via [requester pays](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RequesterPaysBuckets.html).\n", |
| 454 | + "In all these examples, we've limited the returned item count to `10`." |
| 455 | + ] |
| 456 | + }, |
| 457 | + { |
| 458 | + "cell_type": "code", |
| 459 | + "execution_count": 1, |
| 460 | + "id": "e6da363e", |
| 461 | + "metadata": {}, |
| 462 | + "outputs": [ |
| 463 | + { |
| 464 | + "name": "stderr", |
| 465 | + "output_type": "stream", |
| 466 | + "text": [ |
| 467 | + "building \"rustac\"\n", |
| 468 | + "rebuilt and loaded package \"rustac\" in 8.977s\n" |
| 469 | + ] |
| 470 | + }, |
| 471 | + { |
| 472 | + "name": "stdout", |
| 473 | + "output_type": "stream", |
| 474 | + "text": [ |
| 475 | + "Getting the first ten items\n", |
| 476 | + "Got 10 items from the non-partitioned dataset in 7.33 seconds\n", |
| 477 | + "Got 10 items from the partitioned dataset in 1.34 seconds\n" |
| 478 | + ] |
| 479 | + } |
| 480 | + ], |
| 481 | + "source": [ |
| 482 | + "import time\n", |
| 483 | + "from rustac import DuckdbClient\n", |
| 484 | + "\n", |
| 485 | + "client = DuckdbClient()\n", |
| 486 | + "\n", |
| 487 | + "href = \"s3://stac-fastapi-geoparquet-labs-375/its-live/**/*.parquet\"\n", |
| 488 | + "href_partitioned = (\n", |
| 489 | + " \"s3://stac-fastapi-geoparquet-labs-375/its-live-partitioned/**/*.parquet\"\n", |
| 490 | + ")\n", |
| 491 | + "\n", |
| 492 | + "print(\"Getting the first ten items\")\n", |
| 493 | + "start = time.time()\n", |
| 494 | + "items = client.search(href, limit=10)\n", |
| 495 | + "print(\n", |
| 496 | + " f\"Got {len(items)} items from the non-partitioned dataset in {time.time() - start:.2f} seconds\"\n", |
| 497 | + ")\n", |
| 498 | + "\n", |
| 499 | + "start = time.time()\n", |
| 500 | + "items = client.search(href_partitioned, limit=10)\n", |
| 501 | + "print(\n", |
| 502 | + " f\"Got {len(items)} items from the partitioned dataset in {time.time() - start:.2f} seconds\"\n", |
| 503 | + ")" |
| 504 | + ] |
| 505 | + }, |
| 506 | + { |
| 507 | + "cell_type": "code", |
| 508 | + "execution_count": 2, |
| 509 | + "id": "4e631b6d", |
| 510 | + "metadata": {}, |
| 511 | + "outputs": [ |
| 512 | + { |
| 513 | + "name": "stdout", |
| 514 | + "output_type": "stream", |
| 515 | + "text": [ |
| 516 | + "Searching by year\n", |
| 517 | + "Got 10 items from 2024 from the non-partitioned dataset in 19.33 seconds\n", |
| 518 | + "Got 10 items from 2024 the partitioned dataset in 62.54 seconds\n" |
| 519 | + ] |
| 520 | + } |
| 521 | + ], |
| 522 | + "source": [ |
| 523 | + "print(\"Searching by year\")\n", |
| 524 | + "start = time.time()\n", |
| 525 | + "items = client.search(\n", |
| 526 | + " href, limit=10, datetime=\"2024-01-01T00:00:00Z/2024-12-31T23:59:59Z\"\n", |
| 527 | + ")\n", |
| 528 | + "print(\n", |
| 529 | + " f\"Got {len(items)} items from 2024 from the non-partitioned dataset in {time.time() - start:.2f} seconds\"\n", |
| 530 | + ")\n", |
| 531 | + "\n", |
| 532 | + "start = time.time()\n", |
| 533 | + "items = client.search(\n", |
| 534 | + " href_partitioned, limit=10, datetime=\"2024-01-01T00:00:00Z/2024-12-31T23:59:59Z\"\n", |
| 535 | + ")\n", |
| 536 | + "print(\n", |
| 537 | + " f\"Got {len(items)} items from 2024 the partitioned dataset in {time.time() - start:.2f} seconds\"\n", |
| 538 | + ")" |
| 539 | + ] |
| 540 | + }, |
| 541 | + { |
| 542 | + "cell_type": "markdown", |
| 543 | + "id": "e0d8965a", |
| 544 | + "metadata": {}, |
| 545 | + "source": [ |
| 546 | + "The non-partitioned dataset has much smaller files, so the search for the first ten items in 2024 didn't take as long because it didn't have to read in large datasets across the network.\n", |
| 547 | + "Let's use the `year` partitioning filter to speed things up." |
| 548 | + ] |
| 549 | + }, |
| 550 | + { |
| 551 | + "cell_type": "code", |
| 552 | + "execution_count": 3, |
| 553 | + "id": "28b83009", |
| 554 | + "metadata": {}, |
| 555 | + "outputs": [ |
| 556 | + { |
| 557 | + "name": "stdout", |
| 558 | + "output_type": "stream", |
| 559 | + "text": [ |
| 560 | + "Got 10 items from 2024 the partitioned dataset, using `year`, in 1.09 seconds\n" |
| 561 | + ] |
| 562 | + } |
| 563 | + ], |
| 564 | + "source": [ |
| 565 | + "start = time.time()\n", |
| 566 | + "items = client.search(\n", |
| 567 | + " href_partitioned,\n", |
| 568 | + " limit=10,\n", |
| 569 | + " datetime=\"2024-01-01T00:00:00Z/2024-12-31T23:59:59Z\",\n", |
| 570 | + " filter=\"year=2024\",\n", |
| 571 | + ")\n", |
| 572 | + "print(\n", |
| 573 | + " f\"Got {len(items)} items from 2024 the partitioned dataset, using `year`, in {time.time() - start:.2f} seconds\"\n", |
| 574 | + ")" |
| 575 | + ] |
| 576 | + }, |
| 577 | + { |
| 578 | + "cell_type": "markdown", |
| 579 | + "id": "e54bdca1", |
| 580 | + "metadata": {}, |
| 581 | + "source": [ |
| 582 | + "Much better.\n", |
| 583 | + "Now let's try a spatial search.\n", |
| 584 | + "During local testing, we determined that it wasn't even worth it to try against the non-partitioned dataset, as it takes too long." |
| 585 | + ] |
| 586 | + }, |
| 587 | + { |
| 588 | + "cell_type": "code", |
| 589 | + "execution_count": 5, |
| 590 | + "id": "a9fad4df", |
| 591 | + "metadata": {}, |
| 592 | + "outputs": [ |
| 593 | + { |
| 594 | + "name": "stdout", |
| 595 | + "output_type": "stream", |
| 596 | + "text": [ |
| 597 | + "Got 10 items over Helheim Glacier from the partitioned dataset in 9.33 seconds\n" |
| 598 | + ] |
| 599 | + } |
| 600 | + ], |
| 601 | + "source": [ |
| 602 | + "helheim = {\"type\": \"Point\", \"coordinates\": [-38.2, 66.65]}\n", |
| 603 | + "\n", |
| 604 | + "start = time.time()\n", |
| 605 | + "items = client.search(href_partitioned, limit=10, intersects=helheim)\n", |
| 606 | + "print(\n", |
| 607 | + " f\"Got {len(items)} items over Helheim Glacier from the partitioned dataset in {time.time() - start:.2f} seconds\"\n", |
| 608 | + ")" |
| 609 | + ] |
| 610 | + }, |
| 611 | + { |
| 612 | + "cell_type": "markdown", |
| 613 | + "id": "34cf6b59", |
| 614 | + "metadata": {}, |
| 615 | + "source": [ |
| 616 | + "For experimentation, we've also got a [stac-fastapi-geoparquet](https://github.com/stac-utils/stac-fastapi-geoparquet/) server pointing to the same partitioned dataset.\n", |
| 617 | + "Since spatial queries take a lot of data transfer from the DuckDB client to blob storage, is it any faster to query using the **stac-fastapi-geoparquet** lambda?" |
| 618 | + ] |
| 619 | + }, |
| 620 | + { |
| 621 | + "cell_type": "code", |
| 622 | + "execution_count": 7, |
| 623 | + "id": "000e1cd9", |
| 624 | + "metadata": {}, |
| 625 | + "outputs": [ |
| 626 | + { |
| 627 | + "name": "stdout", |
| 628 | + "output_type": "stream", |
| 629 | + "text": [ |
| 630 | + "Got 10 items over Helheim Glacier from the stac-fastapi-geoparquet server in 2.25 seconds\n" |
| 631 | + ] |
| 632 | + } |
| 633 | + ], |
| 634 | + "source": [ |
| 635 | + "import rustac\n", |
| 636 | + "import requests\n", |
| 637 | + "\n", |
| 638 | + "# Make sure the lambda is started\n", |
| 639 | + "response = requests.get(\"https://stac-geoparquet.labs.eoapi.dev\")\n", |
| 640 | + "response.raise_for_status()\n", |
| 641 | + "\n", |
| 642 | + "start = time.time()\n", |
| 643 | + "items = await rustac.search(\n", |
| 644 | + " \"https://stac-geoparquet.labs.eoapi.dev\",\n", |
| 645 | + " collections=[\"its-live-partitioned\"],\n", |
| 646 | + " intersects=helheim,\n", |
| 647 | + " max_items=10,\n", |
| 648 | + ")\n", |
| 649 | + "print(\n", |
| 650 | + " f\"Got {len(items)} items over Helheim Glacier from the stac-fastapi-geoparquet server in {time.time() - start:.2f} seconds\"\n", |
| 651 | + ")" |
| 652 | + ] |
444 | 653 | }
|
445 | 654 | ],
|
446 | 655 | "metadata": {
|
|
0 commit comments