Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
increase websocket buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Feb 7, 2024
1 parent 6f7ee11 commit 8ea4866
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/test/src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resource } from "sst";

export async function handler() {
const body = "a".repeat(1024 * 100);
const body = "a".repeat(1024 * 1024);
return {
statusCode: 200,
body,
Expand Down
4 changes: 4 additions & 0 deletions pkg/platform/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func run() error {
SetTLSConfig(&tls.Config{
InsecureSkipVerify: true,
}).
SetWebsocketOptions(&MQTT.WebsocketOptions{
ReadBufferSize: 1024 * 1000,
WriteBufferSize: 1024 * 1000,
}).
SetCleanSession(false).
SetAutoReconnect(false).
SetConnectionLostHandler(func(c MQTT.Client, err error) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/server/dev/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ func Start(
SetTLSConfig(&tls.Config{
InsecureSkipVerify: true,
}).
SetWebsocketOptions(&MQTT.WebsocketOptions{
ReadBufferSize: 1024 * 1000,
WriteBufferSize: 1024 * 1000,
}).
SetCleanSession(false).
SetAutoReconnect(true).
SetConnectionLostHandler(func(c MQTT.Client, err error) {
slog.Info("mqtt connection lost")
slog.Info("mqtt connection lost", "error", err)
}).
SetReconnectingHandler(func(c MQTT.Client, co *MQTT.ClientOptions) {
slog.Info("mqtt reconnecting")
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/dev/aws/iot_writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
MQTT "github.com/eclipse/paho.mqtt.golang"
)

const BUFFER_SIZE = 1024 * 3
const BUFFER_SIZE = 1024 * 100

type IoTWriter struct {
topic string
Expand Down Expand Up @@ -53,7 +53,7 @@ func (iw *IoTWriter) Write(p []byte) (int, error) {

func (iw *IoTWriter) Flush() error {
if len(iw.buffer) > 0 {
slog.Info("writing to topic", "topic", iw.topic, "data", string(iw.buffer))
slog.Info("writing to topic", "topic", iw.topic, "data", len(iw.buffer))
token := iw.client.Publish(iw.topic, 1, false, iw.buffer)
if token.Wait() && token.Error() != nil {
return token.Error()
Expand Down

0 comments on commit 8ea4866

Please sign in to comment.