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

feat: migrate to API rewrite #351

Merged
merged 26 commits into from
Jan 21, 2024
Merged

feat: migrate to API rewrite #351

merged 26 commits into from
Jan 21, 2024

Conversation

ecxyzzy
Copy link
Member

@ecxyzzy ecxyzzy commented Sep 12, 2023

Summary

Migrate PeterPortal Client to the API rewrite. After [too long] in development, hopefully it will have been worth the wait.

TODO before merging: remove the hardcoded API URLs and update the CI variables to point to the API rewrite.

Test Plan

Overall: Check that the site still works like it does before, and doesn't crash. I tested most cases I could think of, but there are probably some edge and corner cases that I missed since I'm not that familiar with the codebase.

Specific issues:

Known Issues and Next Steps

Issues

Closes #224; closes #238; closes #301; closes #343; closes #344; closes #350.

@ecxyzzy ecxyzzy self-assigned this Sep 15, 2023
@ecxyzzy ecxyzzy changed the title feat: migrate to API rewrite (WIP) feat: migrate to API rewrite Sep 20, 2023
@ecxyzzy ecxyzzy marked this pull request as ready for review September 20, 2023 05:18
Copy link
Member

@js0mmer js0mmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are all of the issues. Lmk if you have any questions or need help with anything. Thanks a ton!

site/src/helpers/util.tsx Outdated Show resolved Hide resolved
api/src/controllers/courses.ts Outdated Show resolved Hide resolved
site/src/component/PrereqTree/PrereqTree.tsx Show resolved Hide resolved
site/src/component/Review/SubReview.tsx Outdated Show resolved Hide resolved
site/src/component/GradeDist/GradeDist.tsx Outdated Show resolved Hide resolved
site/src/pages/SearchPage/CourseHitItem.tsx Outdated Show resolved Hide resolved
site/src/helpers/util.tsx Outdated Show resolved Hide resolved
api/src/helpers/week.ts Outdated Show resolved Hide resolved
site/src/types/types.ts Outdated Show resolved Hide resolved
@ecxyzzy
Copy link
Member Author

ecxyzzy commented Dec 3, 2023

The term indicator issue is tracked on the API end, and I can write a solution for it before this gets merged if needed, but most of the substantial bugs and blockers should be resolved. Thanks for the help and sorry about the delay.

@ecxyzzy ecxyzzy requested a review from js0mmer December 3, 2023 22:30
@js0mmer
Copy link
Member

js0mmer commented Dec 4, 2023

The term indicator issue is tracked on the API end, and I can write a solution for it before this gets merged if needed, but most of the substantial bugs and blockers should be resolved. Thanks for the help and sorry about the delay.

All good, it can wait since we still have an outstanding issue on our end to make the term indicator relevant.

Copy link
Member

@js0mmer js0mmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, search page is much faster now and mostly everything looks to be resolved.

I did notice that AP classes in the prerequisite tree have nonexistent links to course pages but that was preexisting problem so I opened a separate issue for it (#385)

site/src/component/PrereqTree/PrereqTree.tsx Outdated Show resolved Hide resolved
api/src/controllers/courses.ts Outdated Show resolved Hide resolved
site/src/component/ReviewForm/ReviewForm.tsx Show resolved Hide resolved
@ecxyzzy
Copy link
Member Author

ecxyzzy commented Dec 4, 2023

The latest staging build now points to an API staging instance which has the GraphQL change. It still seems quite slow to me which makes me think this is a symptom of a larger issue. Could you confirm whether this is the case?

@js0mmer
Copy link
Member

js0mmer commented Dec 4, 2023

Yeah, still seems slow.

@js0mmer
Copy link
Member

js0mmer commented Dec 5, 2023

Also, the review form is still broken. Seems to just be that the GraphQL response for professors is not mapped properly.
image
ucinetid should be the keys

@js0mmer
Copy link
Member

js0mmer commented Dec 5, 2023

Some really rough performance measurements from throwing print statements in a few places. In general, API rewrite does seem to be a lot slower at responding for course queries, instructors queries seem fine from what I can tell (this is with the batch REST requests for courses and single GraphQL query for instructors). Some improvement could probably be done on our end as well so I might draft up a PR for that.

edit: my brain is fried right now. omitted the api times since i didn't measure them right. total time should be roughly accurate, it varies a lot between runs though

api rewrite

search page

query courses total search time (ms) professors total search time (ms)
Empty 1011 1997
compsci 769
mike 364
compsci 121 668

course page

course total time (ms)
compsci 121 1252

professor page

professor total time (ms)
mikes 1655

original

search page

query courses total search time (ms) professors total search time (ms)
Empty 540 547
compsci 332
mike 211
compsci 121 233

course page

course total time (ms)
compsci 121 664ms

professor page

professor total time (ms)
mikes 1031

@ecxyzzy
Copy link
Member Author

ecxyzzy commented Dec 5, 2023

Thanks for running the numbers. They're definitely worse than I thought; while I suspect it is mostly cold start and/or DB overhead, it's still a pretty hefty penalty even if it doesn't happen that often. I'll look into this further after Wednesday since I should be done with everything except finals by then.

@js0mmer
Copy link
Member

js0mmer commented Dec 6, 2023

Take your time. For future reference, I ran some more robust tests. Max, p95, and p99 stood out to me as significantly higher with the rewrite.

response times (ms) with one request sent every second for 60 seconds

original

route query min max mean median p95 p99
courses first 50 courses alphabetically (result of empty fuzzy search) 261 1055 497 478.3 713.5 727.9
courses COMPSCI121 143 338 192.6 162.4 308 333.7
professors first 50 alphabetically 232 816 434.3 415.8 620.3 671.9
professors mikes 143 363 201.1 162.4 314.2 327.1

rewrite

with batch REST requests for course query

route query min max mean median p95 p99
courses first 50 courses alphabetically (result of empty fuzzy search) 277 2571 408.6 320.6 645.6 1939.5
courses COMPSCI121 229 442 256.8 237.5 314.2 361.5
courses but with extra 3 queries for prereq for, prereq list, instructor history (like course page) COMPSCI121 489 1180 585.2 539.2 742.6 1064.4
professors first 50 alphabetically 283 1513 496.5 376.2 1130.2 1465.9
professors mikes 247 481 281.2 267.8 347.3 459.5
professors but with extra query for courseHistory (like professor page) mikes 496 1863 597.1 539.2 699.4 1587.9

with single GraphQL request for course query

route query min max mean median p95 p99
courses first 50 courses alphabetically (result of empty fuzzy search) 501 2202 728.3 645.6 1200.1 1939.5
courses COMPSCI121 246 472 274 262.5 333.7 376.2
courses but with extra 3 queries for prereq for, prereq list, instructor history (like course page) COMPSCI121 x x x x x x
professors but with extra query for courseHistory (like professor page) mikes 604 982 698.1 671.9 889.1 944

Copy link
Member

@js0mmer js0mmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something's up with the prisma set up on the staging instances. Following endpoints aren't working:

Overall, does seem significantly faster. There is still the persisting slowdown with having to make the extra requests for prerequisite list, prerequisite for, and instructor history on course pages though, especially for those with a lot of prerequisites/prerequisite fors, such as Math 2B.

Below is for Math 2B (tested locally). Requests are for instructor history, prerequisite list, and prerequisite for respectively.
image
Is there a reason why you didn't include the nested GraphQL queries for the api rewrite? I feel like it's been causing a bit of a headache.

I can think of an improvement for this implementation though.
We are requesting much more information than needed for instructor history and prerequisites.
e.g. for each instructor in instructor history

{
    "_0": {
        "name": "Natalia Komarova",
        "shortenedName": "KOMAROVA, N.",
        "ucinetid": "komarova",
        "title": "Professor",
        "department": "Mathematics",
        "schools": [
            "School of Biological Sciences",
            "School of Physical Sciences"
        ],
        "relatedDepartments": [
            "BIO SCI",
            "DEV BIO",
            "ECO EVO",
            "MOL BIO",
            "NEURBIO",
            "CHEM",
            "EARTHSS",
            "MATH",
            "PHY SCI",
            "PHYSICS"
        ],
        "courseHistory": {
            "MATH 2B": [
...

In the prior implementation with the nested queries, we only selected ucinetid, shortened name, and full name for each instructor. I assume doing the same here could result in significant improvements. Same goes for prerequisite list/for, we only selected id, department, number, and title. Whether or not this will be as fast as the single nested query though, I'm not sure.

site/src/component/ReviewForm/ReviewForm.tsx Outdated Show resolved Hide resolved
@ecxyzzy
Copy link
Member Author

ecxyzzy commented Dec 19, 2023

Something's up with the prisma set up on the staging instances. Following endpoints aren't working:

Thanks for pointing this out, I think I forgot to upgrade the query engine version to the one that the Node 20 lambda runtime supports. Pretty sure things should be working now though.

Is there a reason why you didn't include the nested GraphQL queries for the api rewrite? I feel like it's been causing a bit of a headache.

Yeah now that I'm actually integrating the new API with PPC it seems like there was a reason that things were done a certain way. (Go figure.)

I think a way forward that we could consider is to have a separate sub-endpoint that returns nested entries for courses/instructors. I have a rough idea of how to implement this but will still need to work through it, and I'm unsure as to what the performance will look like compared to fetching everything, but it stands to reason that we could reduce the overhead of making multiple HTTP requests.

@ecxyzzy
Copy link
Member Author

ecxyzzy commented Dec 29, 2023

I think the performance issues should be resolved for good this time but can't tell for sure due to regional latency. Could you check on your end?

@ecxyzzy ecxyzzy requested a review from js0mmer December 29, 2023 02:19
Copy link
Member

@js0mmer js0mmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance looks good! Let me know when it's ready for merging and I'll update the actions variables. Thanks.

site/src/component/ReviewForm/ReviewForm.tsx Show resolved Hide resolved
Copy link

Deployed staging instance to https://staging-351.peterportal.org

@js0mmer js0mmer merged commit 0014db1 into master Jan 21, 2024
2 checks passed
@js0mmer js0mmer deleted the api-next-migrate branch January 21, 2024 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants