6DoUD #2: API Development and Major realizations.
What has happened
It has been nearly a week since my first devlog and a few (three) major changes have happened.
First change, I realized I am a stupid dumb idiot. The code I had for finding the path was incredibly inefficient.
Second change, I then realized, again, I am a stupid dumb idiot, the code I had was only finding one path for every set of terms.
And the third major change, I now have an API in place.
Change 1:
When I made the code for the BFS (breadth-first search) I literally just copy-pasted the code from the crawler and changed a few lines. This, was terrible at being BFS.
Apart from a few little bugs that I ironed out early, the model for crawling sucked at BFS. Essentially, the crawler crawled a link, add the hyperlinks in there to the queue and then grabbed the newest term from the queue. However, because there were 24 different threads all running the same code there were tons of locks which were put in place to prevent two threads from processing the same term and therefore wasting time and resources. This however, is not the best for BFS, because the data already exists locally in a database, each term lookup is pretty much instantaneous and therefore having several threads all doing it at once and waiting for each other (due to the locks) is incredibly inefficient. This setup was replaced by a far simpler setup that just does all the things in a loop.
Change 2:
Due to the way I wrote the code, the BFS search was only finding one route for a given set of terms, this was a simple fix and now it works fine. (This change wasn’t major in itself but it made a big difference)
Change 3:
If I was going to incorporate this with a frontend I obviously needed an API. So, that’s what I made.
This is an incredibly simple API made using the FastAPI framework. I didn’t really need to do much for this. I did a bit of restructuring in main.py to help facilitate the new API and then it was as simple as adding a call which needs two inputs, sending it off to main and then returning the result. (As well as adding Prometheus for future analytics)
Example API request + response:
request:
GET /paths?source=toby&target=world+peace
response:
[
[
"toby",
"hard",
"damn",
"emerald",
"world peace"
],
[
"toby",
"t",
"subway",
"windsor",
"world peace"
],
etc..
]
Other thoughts:
I still need to make a lot of stuff, most notable ALL of the frontend. I also spent a LOT of time just messing around and seeing different paths to things instead of doing actual coding. (Dog attached)