Skip to content

Commit ef331d1

Browse files
kachayevztellman
authored andcommitted
Switch to use thread factory from manifold.executor (#426)
1 parent 6665af8 commit ef331d1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
(def other-dependencies
1414
'[[org.clojure/tools.logging "0.4.1" :exclusions [org.clojure/clojure]]
15-
[manifold "0.1.9-alpha2"]
15+
[manifold "0.1.9-SNAPSHOT"]
1616
[byte-streams "0.2.5-alpha2"]
1717
[potemkin "0.4.5"]])
1818

src/aleph/netty.clj

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[byte-streams :as bs]
55
[clojure.tools.logging :as log]
66
[manifold.deferred :as d]
7+
[manifold.executor :as e]
78
[manifold.stream :as s]
89
[manifold.stream.core :as manifold]
910
[primitive-math :as p]
@@ -51,12 +52,16 @@
5152
ResourceLeakDetector$Level]
5253
[java.net URI SocketAddress InetSocketAddress]
5354
[io.netty.util.concurrent
54-
GenericFutureListener Future DefaultThreadFactory]
55+
GenericFutureListener Future]
5556
[java.io InputStream File]
5657
[java.nio ByteBuffer]
5758
[io.netty.util.internal SystemPropertyUtil]
5859
[java.util.concurrent
59-
ConcurrentHashMap CancellationException ScheduledFuture TimeUnit]
60+
ConcurrentHashMap
61+
CancellationException
62+
ScheduledFuture
63+
TimeUnit
64+
ThreadFactory]
6065
[java.util.concurrent.atomic
6166
AtomicLong]
6267
[io.netty.util.internal.logging
@@ -721,18 +726,26 @@
721726
(let [cpu-count (->> (Runtime/getRuntime) (.availableProcessors))]
722727
(max 1 (SystemPropertyUtil/getInt "io.netty.eventLoopThreads" (* cpu-count 2)))))
723728

729+
(defn ^ThreadFactory enumerating-thread-factory [prefix daemon?]
730+
(let [num-threads (atom 0)]
731+
(e/thread-factory
732+
#(str prefix "-" (swap! num-threads inc))
733+
(deliver (promise) nil)
734+
nil
735+
daemon?)))
736+
724737
(def ^String client-event-thread-pool-name "aleph-netty-client-event-pool")
725738

726739
(def epoll-client-group
727740
(delay
728741
(let [thread-count (get-default-event-loop-threads)
729-
thread-factory (DefaultThreadFactory. client-event-thread-pool-name true)]
742+
thread-factory (enumerating-thread-factory client-event-thread-pool-name true)]
730743
(EpollEventLoopGroup. (long thread-count) thread-factory))))
731744

732745
(def nio-client-group
733746
(delay
734747
(let [thread-count (get-default-event-loop-threads)
735-
thread-factory (DefaultThreadFactory. client-event-thread-pool-name true)]
748+
thread-factory (enumerating-thread-factory client-event-thread-pool-name true)]
736749
(NioEventLoopGroup. (long thread-count) thread-factory))))
737750

738751
(defn convert-address-types [address-types]
@@ -913,7 +926,7 @@
913926
epoll?]
914927
(let [num-cores (.availableProcessors (Runtime/getRuntime))
915928
num-threads (* 2 num-cores)
916-
thread-factory (DefaultThreadFactory. "aleph-netty-server-event-pool" false)
929+
thread-factory (enumerating-thread-factory "aleph-netty-server-event-pool" false)
917930
closed? (atom false)
918931

919932
^EventLoopGroup group

0 commit comments

Comments
 (0)