Merge pull request #13570 from thingsboard/fix/oom

Memory usage improvements
This commit is contained in:
Viacheslav Klimov 2025-06-19 08:07:03 +03:00 committed by GitHub
commit a55f4d386a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 26 additions and 44 deletions

View File

@ -237,8 +237,14 @@ public final class TbActorMailbox implements TbActorCtx {
try { try {
ready.set(NOT_READY); ready.set(NOT_READY);
actor.destroy(stopReason, cause); actor.destroy(stopReason, cause);
highPriorityMsgs.forEach(msg -> msg.onTbActorStopped(stopReason)); highPriorityMsgs.removeIf(msg -> {
normalPriorityMsgs.forEach(msg -> msg.onTbActorStopped(stopReason)); msg.onTbActorStopped(stopReason);
return true;
});
normalPriorityMsgs.removeIf(msg -> {
msg.onTbActorStopped(stopReason);
return true;
});
} catch (Throwable t) { } catch (Throwable t) {
log.warn("[{}] Failed to destroy actor: ", selfId, t); log.warn("[{}] Failed to destroy actor: ", selfId, t);
} }

View File

@ -32,8 +32,8 @@ public class AdminSettings extends BaseData<AdminSettingsId> implements HasTenan
@NoXss @NoXss
@Length(fieldName = "key") @Length(fieldName = "key")
private String key; private String key;
private transient JsonNode jsonValue; private JsonNode jsonValue;
public AdminSettings() { public AdminSettings() {
super(); super();
} }
@ -41,7 +41,7 @@ public class AdminSettings extends BaseData<AdminSettingsId> implements HasTenan
public AdminSettings(AdminSettingsId id) { public AdminSettings(AdminSettingsId id) {
super(id); super(id);
} }
public AdminSettings(AdminSettings adminSettings) { public AdminSettings(AdminSettings adminSettings) {
super(adminSettings); super(adminSettings);
this.tenantId = adminSettings.getTenantId(); this.tenantId = adminSettings.getTenantId();

View File

@ -25,9 +25,9 @@ public abstract class BaseData<I extends UUIDBased> extends IdBased<I> implement
private static final long serialVersionUID = 5422817607129962637L; private static final long serialVersionUID = 5422817607129962637L;
public static final ObjectMapper mapper = new ObjectMapper(); public static final ObjectMapper mapper = new ObjectMapper();
protected long createdTime; protected long createdTime;
public BaseData() { public BaseData() {
super(); super();
} }
@ -35,7 +35,7 @@ public abstract class BaseData<I extends UUIDBased> extends IdBased<I> implement
public BaseData(I id) { public BaseData(I id) {
super(id); super(id);
} }
public BaseData(BaseData<I> data) { public BaseData(BaseData<I> data) {
super(data.getId()); super(data.getId());
this.createdTime = data.getCreatedTime(); this.createdTime = data.getCreatedTime();
@ -53,7 +53,7 @@ public abstract class BaseData<I extends UUIDBased> extends IdBased<I> implement
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + (int) (createdTime ^ (createdTime >>> 32)); result = prime * result + Long.hashCode(createdTime);
return result; return result;
} }

View File

@ -68,8 +68,8 @@ public class Dashboard extends DashboardInfo implements ExportableEntity<Dashboa
} }
@Schema(description = "JSON object with main configuration of the dashboard: layouts, widgets, aliases, etc. " + @Schema(description = "JSON object with main configuration of the dashboard: layouts, widgets, aliases, etc. " +
"The JSON structure of the dashboard configuration is quite complex. " + "The JSON structure of the dashboard configuration is quite complex. " +
"The easiest way to learn it is to export existing dashboard to JSON." "The easiest way to learn it is to export existing dashboard to JSON."
, implementation = com.fasterxml.jackson.databind.JsonNode.class) , implementation = com.fasterxml.jackson.databind.JsonNode.class)
public JsonNode getConfiguration() { public JsonNode getConfiguration() {
return configuration; return configuration;

View File

@ -62,9 +62,7 @@ public class RuleNode extends BaseDataWithAdditionalInfo<RuleNodeId> implements
@Schema(description = "Version of rule node configuration. ", example = "0") @Schema(description = "Version of rule node configuration. ", example = "0")
private int configurationVersion; private int configurationVersion;
@Schema(description = "JSON with the rule node configuration. Structure depends on the rule node implementation.", implementation = JsonNode.class) @Schema(description = "JSON with the rule node configuration. Structure depends on the rule node implementation.", implementation = JsonNode.class)
private transient JsonNode configuration; private JsonNode configuration;
@JsonIgnore
private byte[] configurationBytes;
private RuleNodeId externalId; private RuleNodeId externalId;
@ -92,14 +90,6 @@ public class RuleNode extends BaseDataWithAdditionalInfo<RuleNodeId> implements
return name; return name;
} }
public JsonNode getConfiguration() {
return BaseDataWithAdditionalInfo.getJson(() -> configuration, () -> configurationBytes);
}
public void setConfiguration(JsonNode data) {
setJson(data, json -> this.configuration = json, bytes -> this.configurationBytes = bytes);
}
@Schema(description = "JSON object with the Rule Node Id. " + @Schema(description = "JSON object with the Rule Node Id. " +
"Specify this field to update the Rule Node. " + "Specify this field to update the Rule Node. " +
"Referencing non-existing Rule Node Id will cause error. " + "Referencing non-existing Rule Node Id will cause error. " +

View File

@ -15,20 +15,15 @@
*/ */
package org.thingsboard.server.common.data.settings; package org.thingsboard.server.common.data.settings;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.ToString;
import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.validation.Length; import org.thingsboard.server.common.data.validation.Length;
import org.thingsboard.server.common.data.validation.NoXss; import org.thingsboard.server.common.data.validation.NoXss;
import java.io.Serializable; import java.io.Serializable;
import static org.thingsboard.server.common.data.BaseDataWithAdditionalInfo.getJson;
import static org.thingsboard.server.common.data.BaseDataWithAdditionalInfo.setJson;
@Schema @Schema
@Data @Data
public class UserSettings implements Serializable { public class UserSettings implements Serializable {
@ -43,20 +38,9 @@ public class UserSettings implements Serializable {
@Length(fieldName = "type", max = 50) @Length(fieldName = "type", max = 50)
private UserSettingsType type; private UserSettingsType type;
@Schema(description = "JSON object with user settings.",implementation = com.fasterxml.jackson.databind.JsonNode.class) @Schema(description = "JSON object with user settings.", implementation = com.fasterxml.jackson.databind.JsonNode.class)
@NoXss @NoXss
@Length(fieldName = "settings", max = 100000) @Length(fieldName = "settings", max = 100000)
private transient JsonNode settings; private JsonNode settings;
@JsonIgnore
@ToString.Exclude
private byte[] settingsBytes;
public JsonNode getSettings() {
return getJson(() -> settings, () -> settingsBytes);
}
public void setSettings(JsonNode settings) {
setJson(settings, json -> this.settings = json, bytes -> this.settingsBytes = bytes);
}
} }

View File

@ -21,15 +21,17 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.id.WidgetTypeId; import org.thingsboard.server.common.data.id.WidgetTypeId;
import java.util.Optional; import java.util.Optional;
@EqualsAndHashCode(callSuper = true)
@Data @Data
public class WidgetType extends BaseWidgetType { public class WidgetType extends BaseWidgetType {
@Schema(description = "Complex JSON object that describes the widget type", accessMode = Schema.AccessMode.READ_ONLY) @Schema(description = "Complex JSON object that describes the widget type", accessMode = Schema.AccessMode.READ_ONLY)
private transient JsonNode descriptor; private JsonNode descriptor;
public WidgetType() { public WidgetType() {
super(); super();

View File

@ -26,7 +26,7 @@ import java.security.GeneralSecurityException;
import java.security.KeyStore; import java.security.KeyStore;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = true)
public class KeystoreSslCredentials extends AbstractSslCredentials { public class KeystoreSslCredentials extends AbstractSslCredentials {
private String type; private String type;

View File

@ -46,7 +46,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = true)
public class PemSslCredentials extends AbstractSslCredentials { public class PemSslCredentials extends AbstractSslCredentials {
private static final String DEFAULT_KEY_ALIAS = "server"; private static final String DEFAULT_KEY_ALIAS = "server";
@ -72,7 +72,7 @@ public class PemSslCredentials extends AbstractSslCredentials {
try (InputStream inStream = ResourceUtils.getInputStream(this, this.certFile)) { try (InputStream inStream = ResourceUtils.getInputStream(this, this.certFile)) {
try (PEMParser pemParser = new PEMParser(new InputStreamReader(inStream))) { try (PEMParser pemParser = new PEMParser(new InputStreamReader(inStream))) {
Object object; Object object;
while((object = pemParser.readObject()) != null) { while ((object = pemParser.readObject()) != null) {
if (object instanceof X509CertificateHolder) { if (object instanceof X509CertificateHolder) {
X509Certificate x509Cert = certConverter.getCertificate((X509CertificateHolder) object); X509Certificate x509Cert = certConverter.getCertificate((X509CertificateHolder) object);
certificates.add(x509Cert); certificates.add(x509Cert);