Skip to content

Commit 65b7033

Browse files
authored
[Core] Reduce port system load by comparing entities and upserting changed entities for all types of integrations (#1336)
# Description What - Introduced a new entity diff resolver to reduce port system load by comparing entities and upserting changed entities only for all types of integrations (not only saas) Why - after a poc , we see that the fix works well and we want to have it for all the integrations, not only saas How - removed the if ocean saas check ## Type of change - [ ] New feature (non-breaking change which adds functionality) ### Core testing checklist - [ ] Integration able to create all default resources from scratch - [ ] Resync finishes successfully - [ ] Resync able to create entities - [ ] Resync able to update entities - [ ] Resync able to detect and delete entities - [ ] Scheduled resync able to abort existing resync and start a new one - [ ] Tested with at least 2 integrations from scratch - [ ] Tested with Kafka and Polling event listeners - [ ] Tested deletion of entities that don't pass the selector
1 parent be90ed4 commit 65b7033

File tree

5 files changed

+159
-240
lines changed

5 files changed

+159
-240
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
<!-- towncrier release notes start -->
9+
## 0.18.4 (2025-01-22)
10+
11+
### Improvements
12+
13+
- added check diff entitites to reduce load from port to all integrations
14+
915
## 0.18.3 (2025-01-22)
1016

1117
### Improvements

port_ocean/clients/port/mixins/entities.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def __init__(self, auth: PortAuthentication, client: httpx.AsyncClient):
2222
# Semaphore is used to limit the number of concurrent requests to port, to avoid overloading it.
2323
# The number of concurrent requests is set to 90% of the max connections limit, to leave some room for other
2424
# requests that are not related to entities.
25-
self.semaphore = asyncio.Semaphore(round(0.9 * PORT_HTTP_MAX_CONNECTIONS_LIMIT))
25+
self.semaphore = asyncio.Semaphore(
26+
round(0.5 * PORT_HTTP_MAX_CONNECTIONS_LIMIT)
27+
) # 50% of the max connections limit in order to avoid overloading port
2628

2729
async def upsert_entity(
2830
self,

port_ocean/core/integrations/mixins/sync_raw.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -220,33 +220,27 @@ async def _register_resource_raw(
220220
)
221221
modified_objects = []
222222

223-
if ocean.app.is_saas():
224-
try:
225-
changed_entities = await self._map_entities_compared_with_port(
226-
objects_diff[0].entity_selector_diff.passed,
227-
resource,
228-
user_agent_type
223+
try:
224+
changed_entities = await self._map_entities_compared_with_port(
225+
objects_diff[0].entity_selector_diff.passed,
226+
resource,
227+
user_agent_type
228+
)
229+
if changed_entities:
230+
logger.info("Upserting changed entities", changed_entities=len(changed_entities),
231+
total_entities=len(objects_diff[0].entity_selector_diff.passed))
232+
await self.entities_state_applier.upsert(
233+
changed_entities, user_agent_type
229234
)
230-
231-
if changed_entities:
232-
logger.info("Upserting changed entities", changed_entities=len(changed_entities),
233-
total_entities=len(objects_diff[0].entity_selector_diff.passed))
234-
await self.entities_state_applier.upsert(
235-
changed_entities, user_agent_type
236-
)
237-
else:
238-
logger.info("Entities in batch didn't changed since last sync, skipping", total_entities=len(objects_diff[0].entity_selector_diff.passed))
239-
240-
modified_objects = [ocean.port_client._reduce_entity(entity) for entity in objects_diff[0].entity_selector_diff.passed]
241-
except Exception as e:
242-
logger.warning(f"Failed to resolve batch entities with Port, falling back to upserting all entities: {str(e)}")
243-
modified_objects = await self.entities_state_applier.upsert(
244-
objects_diff[0].entity_selector_diff.passed, user_agent_type
245-
)
246-
else:
235+
else:
236+
logger.info("Entities in batch didn't changed since last sync, skipping", total_entities=len(objects_diff[0].entity_selector_diff.passed))
237+
modified_objects = [ocean.port_client._reduce_entity(entity) for entity in objects_diff[0].entity_selector_diff.passed]
238+
except Exception as e:
239+
logger.warning(f"Failed to resolve batch entities with Port, falling back to upserting all entities: {str(e)}")
247240
modified_objects = await self.entities_state_applier.upsert(
248241
objects_diff[0].entity_selector_diff.passed, user_agent_type
249-
)
242+
)
243+
250244
return CalculationResult(
251245
objects_diff[0].entity_selector_diff._replace(passed=modified_objects),
252246
errors=objects_diff[0].errors,

0 commit comments

Comments
 (0)