Speed up lookups using a cache map #12

Closed
opened 2024-02-26 07:54:33 +01:00 by tom · 1 comment
Owner

Currently, the specified IP address is converted to the integer ipnum and then the net address is calculated from "/24" because there are no public networks smaller than /24. If there is no match, the integer of the net address ipnetnum is reduced until there is a match in the database or until 0 is reached. For IP addresses from the same network, the reduction time can be saved by caching.

Currently, the specified IP address is converted to the integer `ipnum` and then the net address is calculated from "/24" because there are no public networks smaller than /24. If there is no match, the integer of the net address `ipnetnum` is reduced until there is a match in the database or until 0 is reached. For IP addresses from the same network, the reduction time can be saved by caching.
tom self-assigned this 2024-02-26 07:54:33 +01:00
Author
Owner

The cache seems to work and reduces the lookup / calculation time.

with cache:

2024/02/26 09:34:01 [DESKTOP-D6N50LO/BAc0JvBbJ1-000004] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57084 - 200 164B in 230.604µs
2024/02/26 09:34:02 [DESKTOP-D6N50LO/BAc0JvBbJ1-000005] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57090 - 200 164B in 126.192µs
2024/02/26 09:34:03 [DESKTOP-D6N50LO/BAc0JvBbJ1-000006] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57106 - 200 164B in 59.111µs
2024/02/26 09:34:03 [DESKTOP-D6N50LO/BAc0JvBbJ1-000007] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57120 - 200 164B in 133.362µs
2024/02/26 09:34:04 [DESKTOP-D6N50LO/BAc0JvBbJ1-000008] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57122 - 200 164B in 64.282µs
2024/02/26 09:34:06 [DESKTOP-D6N50LO/BAc0JvBbJ1-000009] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57134 - 200 164B in 90.632µs
2024/02/26 09:34:06 [DESKTOP-D6N50LO/BAc0JvBbJ1-000010] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57140 - 200 164B in 92.871µs
2024/02/26 09:34:07 [DESKTOP-D6N50LO/BAc0JvBbJ1-000011] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57156 - 200 164B in 78.251µs
2024/02/26 09:34:07 [DESKTOP-D6N50LO/BAc0JvBbJ1-000012] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57170 - 200 164B in 79.041µs
2024/02/26 09:34:08 [DESKTOP-D6N50LO/BAc0JvBbJ1-000013] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57186 - 200 164B in 98.422µs

without cache:

2024/02/26 09:36:29 [DESKTOP-D6N50LO/K1oALlJWXF-000041] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:50354 - 200 164B in 206.131µs
2024/02/26 09:36:30 [DESKTOP-D6N50LO/K1oALlJWXF-000042] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:50362 - 200 164B in 356.411µs
2024/02/26 09:36:30 [DESKTOP-D6N50LO/K1oALlJWXF-000043] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60294 - 200 164B in 219.911µs
2024/02/26 09:36:30 [DESKTOP-D6N50LO/K1oALlJWXF-000044] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60308 - 200 164B in 227.381µs
2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000045] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60316 - 200 164B in 236.221µs
2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000046] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60330 - 200 164B in 176.811µs
2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000047] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60342 - 200 164B in 222.17µs
2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000048] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60356 - 200 164B in 193.901µs
2024/02/26 09:36:32 [DESKTOP-D6N50LO/K1oALlJWXF-000049] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60360 - 200 164B in 180.14µs
2024/02/26 09:36:32 [DESKTOP-D6N50LO/K1oALlJWXF-000050] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60374 - 200 164B in 296.581µs
2024/02/26 09:36:33 [DESKTOP-D6N50LO/K1oALlJWXF-000051] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60390 - 200 164B in 186.461µs
The cache seems to work and reduces the lookup / calculation time. with cache: ``` 2024/02/26 09:34:01 [DESKTOP-D6N50LO/BAc0JvBbJ1-000004] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57084 - 200 164B in 230.604µs 2024/02/26 09:34:02 [DESKTOP-D6N50LO/BAc0JvBbJ1-000005] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57090 - 200 164B in 126.192µs 2024/02/26 09:34:03 [DESKTOP-D6N50LO/BAc0JvBbJ1-000006] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57106 - 200 164B in 59.111µs 2024/02/26 09:34:03 [DESKTOP-D6N50LO/BAc0JvBbJ1-000007] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57120 - 200 164B in 133.362µs 2024/02/26 09:34:04 [DESKTOP-D6N50LO/BAc0JvBbJ1-000008] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57122 - 200 164B in 64.282µs 2024/02/26 09:34:06 [DESKTOP-D6N50LO/BAc0JvBbJ1-000009] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57134 - 200 164B in 90.632µs 2024/02/26 09:34:06 [DESKTOP-D6N50LO/BAc0JvBbJ1-000010] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57140 - 200 164B in 92.871µs 2024/02/26 09:34:07 [DESKTOP-D6N50LO/BAc0JvBbJ1-000011] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57156 - 200 164B in 78.251µs 2024/02/26 09:34:07 [DESKTOP-D6N50LO/BAc0JvBbJ1-000012] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57170 - 200 164B in 79.041µs 2024/02/26 09:34:08 [DESKTOP-D6N50LO/BAc0JvBbJ1-000013] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:57186 - 200 164B in 98.422µs ``` without cache: ``` 2024/02/26 09:36:29 [DESKTOP-D6N50LO/K1oALlJWXF-000041] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:50354 - 200 164B in 206.131µs 2024/02/26 09:36:30 [DESKTOP-D6N50LO/K1oALlJWXF-000042] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:50362 - 200 164B in 356.411µs 2024/02/26 09:36:30 [DESKTOP-D6N50LO/K1oALlJWXF-000043] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60294 - 200 164B in 219.911µs 2024/02/26 09:36:30 [DESKTOP-D6N50LO/K1oALlJWXF-000044] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60308 - 200 164B in 227.381µs 2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000045] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60316 - 200 164B in 236.221µs 2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000046] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60330 - 200 164B in 176.811µs 2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000047] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60342 - 200 164B in 222.17µs 2024/02/26 09:36:31 [DESKTOP-D6N50LO/K1oALlJWXF-000048] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60356 - 200 164B in 193.901µs 2024/02/26 09:36:32 [DESKTOP-D6N50LO/K1oALlJWXF-000049] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60360 - 200 164B in 180.14µs 2024/02/26 09:36:32 [DESKTOP-D6N50LO/K1oALlJWXF-000050] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60374 - 200 164B in 296.581µs 2024/02/26 09:36:33 [DESKTOP-D6N50LO/K1oALlJWXF-000051] "GET http://127.0.0.1:8080/api/v1/location/1.13.191.30 HTTP/1.1" from 127.0.0.1:60390 - 200 164B in 186.461µs ```
tom closed this issue 2024-02-26 09:55:06 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: yolokube/country-geo-locations#12
No description provided.