本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Neptune Serverless 的活動訊號組態
搭配 Neptune Serverless 使用 Gremlin WebSocket 用戶端時,您需要適當設定用戶端的 ping 間隔,以在擴展事件期間維持穩定的連線。Gremlin 用戶端使用 WebSocket 連線,並傳送定期 ping 以確認連線作用中。用戶端預期伺服器會在 ping 間隔時間範圍內回應。如果伺服器未回應,用戶端會自動關閉連線。
對於 Neptune 佈建的執行個體,我們建議將 ping 間隔設定為 5 秒。對於 Neptune Serverless 叢集,我們建議將 ping 間隔設定為至少 20 秒,以適應擴展操作期間的潛在延遲。此參數控制用戶端在寫入伺服器之間等待多久,再傳送 ping 以確認連線仍然作用中。
此參數的組態會根據用戶端實作而有所不同:
Java 用戶端組態
針對 Java TinkerPop Gremlin 用戶端,設定 keepAliveInterval 參數:
Cluster.Builder builder = Cluster.build() .addContactPoint(endpoint) .keepAliveInterval(20000); // Configure ping interval in milliseconds
如需 Java 驅動程式組態的詳細資訊,請參閱 Java TinkerPop 文件
Go 用戶端組態
針對 Gremlin Go 用戶端,設定 KeepAliveInterval 參數:
rc, err := driver.NewDriverRemoteConnection(endpoint, func(settings *driver.DriverRemoteConnectionSettings) { settings.TraversalSource = "g" settings.AuthInfo = auth settings.KeepAliveInterval = 20 * time.Second // Configure ping interval ... })
如需 Go 驅動程式組態的詳細資訊,請參閱 Go TinkerPop 文件
JavaScript/Node.js 用戶端組態
針對 JavaScript/Node.js Gremlin 用戶端,設定 pingInterval 參數:
const gremlin = require('gremlin'); const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection; const connection = new DriverRemoteConnection(endpoint, { traversalSource: 'g', pingInterval: 20000 // Configure ping interval in milliseconds });
如需 JavaScript 驅動程式組態的詳細資訊,請參閱 JavaScript TinkerPop 文件
Python 用戶端組態
對於 Python Gremlin 用戶端,ping 間隔通常在傳輸層進行管理。如需組態選項,請參閱特定的傳輸實作文件:
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection g = traversal().with_remote( DriverRemoteConnection('wss://your-neptune-endpoint:your-neptune-port/gremlin','g', transport_factory=lambda: AiohttpTransport(read_timeout=60, write_timeout=20, heartbeat=20, // Configure heartbeat call_from_event_loop=True, max_content_length=100*1024*1024, ssl_options=ssl.create_default_context(Purpose.CLIENT_AUTH))))
如需 Python 驅動程式組態的詳細資訊,請參閱 Python TinkerPop 文件
此組態可確保用戶端在 Neptune Serverless 擴展事件期間維持連線穩定性,防止不必要的連線關閉並改善應用程式可靠性。