1. 程式人生 > >spark redis 中碰到java.net.SocketTimeoutException: Read timed out問題的解決

spark redis 中碰到java.net.SocketTimeoutException: Read timed out問題的解決

最近在寫入redis的時候,程式跑著跑著會發現碰到這樣的問題。

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
    at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202)
    at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
    at redis.clients.jedis.Protocol.process(Protocol.java:151)
    at redis.clients.jedis.Protocol.read(Protocol.java:215)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:276)
    at redis.clients.jedis.Connection.getMultiBulkReply(Connection.java:269)
    at redis.clients.jedis.Jedis.lrange(Jedis.java:935)
    at com.redislabs.provider.redis.rdd.RedisListRDD$$anonfun$getLIST$1$$anonfun$3.apply(RedisRDD.scala:98)
    at com.redislabs.provider.redis.rdd.RedisListRDD$$anonfun$getLIST$1$$anonfun$3.apply(RedisRDD.scala:98)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
    at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
    at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
    at scala.collection.mutable.ArrayOps$ofRef.flatMap(ArrayOps.scala:186)
由於spark採用的是jedis來連線的,因此也就說明是jedis的問題。

針對這一問題,之前直接都是利用

val client = new Jedis(ip, port)的方法,巢狀在dataframe.foreach()中的方式。

由於之前部署是流式的資料處理,所以每次處理間隔都非常短,因此沒有任何問題。但是這回為了檢視一個數據想快取到spark的時候,發現了這個BUG。也才具體發現以前程式設定的不合理的地方。

還好,Jedis提供了這種解決方法。

  • public JedisPool(final GenericObjectPoolConfig poolConfig, final String host, final int port, final int timeout)
  • public JedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port, int timeout, final String password, final int database)
  • public JedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port, int timeout, final String password, final int database, final String clientName)
採用這種池化的概念,可以來設定裡面的timeout引數,預設是2000。

根據大概程式寫入redis的資料量和時長來設定即可。

由於本來寫入的資料量大概有7億多條記錄,為了方便,拆分了400個小片斷分開寫入,再用上述預設設定,也能夠通過。

程式碼片斷可以如下:

Jediscommands jediscommands;
JedisPool jedisPool;
JedisPoolConfig config = new JedisPoolConfig()

String ip = "***"
int port = 6379
long timeOut = 2000
String auth = "***"
JedisPool jedisPool = new JedisPool(config,ip,port,timeOut,auth)

Jedis jedis = jedisPool.getResource();

當前,也只可以對JedisPoolConfig進行設定。

相關推薦

spark redis 碰到java.net.SocketTimeoutException: Read timed out問題的解決

最近在寫入redis的時候,程式跑著跑著會發現碰到這樣的問題。 redis.clients.jedis.exceptions.JedisConnectionException: java.net.So

tomcat servlet java.net.SocketTimeoutException: Read timed out 解決辦法

最近在整一個拍照上傳,手機通過無線網路上傳照片到伺服器,伺服器端是JAVA寫的servlet;思路是將較大的圖片分塊傳送到伺服器進行拼裝。但發現服務端在讀取圖片資料時候( InputStream.read)多半是java.net.SocketTimeoutException

java.net.SocketTimeoutException: Read timed out

enc awl lang erp 了解 nag request 調用 sop 1.問題展示: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRea

java.net.SocketTimeoutException: Read timed out解決辦法

產生問題的環境:ssm+mysql+gridFS+tomcat 問題程式碼段: public void write(OutputStream os, InputStream is) { try (BufferedOutputStream bos = new BufferedOutputS

springboot+thrift超時 java.net.SocketTimeoutException: Read timed out

報錯資訊如下: org.apache.thrift.transport.TTransportException: java.net.SocketTimeoutException: Read timed out at org.apache.thrift.transport.TIOStreamTransport

Feign服務間呼叫超時 Caused by: java.net.SocketTimeoutException: Read timed out

今天,在調式服務間呼叫的時候遇到以下問題  : Caused by: java.net.SocketTimeoutException: Read timed out   百度查了一下,預設的請求時間為1秒,超過這個

報表使用hive資料來源報java.net.SocketTimeoutException: Read timed out

資料庫表的資料量大概50W左右,在報表設計器下建立了hive的資料來源,連線正常,由於資料量比較大,就用了潤乾報表的大資料報表功能,報表設定好後,釋出到頁面中報錯: 資料集ds1中,SQL語句SELECT *  FROM general_bil::org.apache.th

java.net.SocketTimeoutException: Read timed out解決辦法 android平臺 騰訊微博開發

剛接手騰訊微博,做了個小DEMO。公司網路有代理。發照片時一半左右傳送失敗,錯誤資訊如下 W/System.err(31723): java.net.SocketTimeoutException: Read timed out W/System.err(31723):   

edis.clients.jedis.exceptions.JedisConnectionException: java.Net.SocketTimeoutException: Read timed

當我們獲取連線後對redis進行操作時,丟擲redis.clients.jedis.exceptions.JedisConnectionException: java.NET.SocketTimeoutException: Read timed out異常。 異常程式碼如

阿里雲Cont_OS_7連線Reids報錯:java.net.SocketTimeoutException: connect timed out

解決方案1: 將redis.conf中的bind127.0.0.1 用"#"註釋掉; 解決方案2: 關閉防火牆; 關閉命令: systemctl stop firewalld.service 啟動命令: systemctl start firewalld.ser

FastDFS(fdfs)遇到的坑之一,本地fastdfs-client-java開發上傳圖片報錯:java.net.SocketTimeoutException: connect timed out

前置: 我在伺服器上配置了FDFS服務, 伺服器上上傳等測試都通過了,沒問題,後來到本地開發, 用fastdfs-client-java-1.27.jar開發包來連結伺服器,上傳圖片報錯: java.net.SocketTimeoutException: connect

Caused by: java.net.ConnectException: Connection timed out: connect

spring boot專案整合mybatis時連線資料庫報錯 Caused by: java.net.ConnectException: Connection timed out: connect 我的是因為linux上的防火牆及3306埠沒開放 參考: https://blog

【已解決java.net.ConnectException: Connection timed out: no further information

前言: 今天連線zookeepter的時候出現問題(上午連線的時候還沒問題的,下午就出現了問題,很是無奈) 報錯資訊如下: java.net.ConnectException: Connection timed out: no further information at

connection.getOutputStream() 報java.net.ConnectException: Connection timed out: connect

摘自stackoverflow Connection timeouts (assuming a local network and several client machines) typically result from a) some kind of firewall on the w

java.net.connectexception:connection timed out

我出現這個問題是由於專案中的gradle版本升級了,要下一個gradle-2.8的包,然而下不了。 首先我嘗試去ping一下網路,看看是不是網路出了問題, 此時出現了這種問題,我再去檢查一下我的DNS

壓測netty框架,返回少量java.net.ConnectException:Connection timed out,優化程式碼

xx專案需要做效能測試,開發端主要是netty框架,500併發TPS能達到7000+,但是返回少量  Connection timed out,原因有可能是程式碼有問題,也有可能僅是客戶端主動關閉了連線,導致服務端的寫失敗,linux伺服器本身無法處理如此大量請求,監控到客

讓人無語的java.net.ConnectException: Connection timed out: connect

今天上午在做s2sh專案的時候,突然報了這個錯誤。我查資料嘗試,重新部署專案,重啟Myecilpse,重啟電腦,搞了半天,還是沒有解決。結果中午回宿舍在筆記本上部署了一下,發現沒錯誤。我就睡了會,回去發現好了。真讓人蛋疼。如果你也遇到這問題,希望這對你也有效,先休息一下吧。

java.net.ConnectException: Connection timed out: connect原因及解決 java設定代理http請求

今天用URLConnection進行http請求時,返回錯誤如下: java.net.ConnectException: Connection timed out: connect  at java.net.PlainSocketImpl.socketConnect(Nat

java.net.ConnectException: Connection timed out: connect 錯誤

java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSock

javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection timed out: connect

最好 端口號 圖片 col alt style url 解決 ava 本地測試向服務器中ActiveMQ添加隊列數據,報錯連接超時 解決: 查看服務器端口號是否存在,(最好是0.0.0.0格式的,雖然暫時還不知道為啥得這個格式) 通過telnet測試該端口不通(6