Skip to content

Commit 70404d4

Browse files
author
Andrew Fogarty
committed
Address some of Terry's comments.
1 parent 4c695b5 commit 70404d4

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

src/csharp/Microsoft.Spark.E2ETest/IpcTests/JvmThreadPoolGarbageCollectorTests.cs renamed to src/csharp/Microsoft.Spark.E2ETest/IpcTests/JvmThreadPoolGCTests.cs

+15-11
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace Microsoft.Spark.E2ETest.IpcTests
1313
{
1414
[Collection("Spark E2E Tests")]
15-
public class JvmThreadPoolGarbageCollectorTests
15+
public class JvmThreadPoolGCTests
1616
{
1717
private readonly SparkSession _spark;
1818
private readonly IJvmBridge _jvmBridge;
1919

20-
public JvmThreadPoolGarbageCollectorTests(SparkFixture fixture)
20+
public JvmThreadPoolGCTests(SparkFixture fixture)
2121
{
2222
_spark = fixture.Spark;
2323
_jvmBridge = ((IJvmObjectReferenceProvider)_spark).Reference.Jvm;
@@ -42,7 +42,7 @@ void testChildThread(string appName)
4242

4343
// Since we are in the child thread, GetActiveSession() should return the child
4444
// SparkSession.
45-
var activeSession = SparkSession.GetActiveSession();
45+
SparkSession activeSession = SparkSession.GetActiveSession();
4646
Assert.NotNull(activeSession);
4747
Assert.Equal(appName, activeSession.Conf().Get("spark.app.name", null));
4848
});
@@ -51,7 +51,7 @@ void testChildThread(string appName)
5151
thread.Join();
5252
}
5353

54-
for (var i = 0; i < 5; i++)
54+
for (var i = 0; i < 5; ++i)
5555
{
5656
testChildThread(i.ToString());
5757
}
@@ -60,12 +60,12 @@ void testChildThread(string appName)
6060
}
6161

6262
/// <summary>
63-
/// Monitor a thread via the JvmThreadPoolGarbageCollector.
63+
/// Monitor a thread via the JvmThreadPoolGC.
6464
/// </summary>
6565
[Fact]
66-
public void TestMonitorThread()
66+
public void TestTryAddThread()
6767
{
68-
var threadPool = new JvmThreadPoolGarbageCollector(_jvmBridge, TimeSpan.FromMinutes(30));
68+
using var threadPool = new JvmThreadPoolGC(_jvmBridge, TimeSpan.FromMinutes(30));
6969

7070
var thread = new Thread(() => _spark.Sql("SELECT TRUE"));
7171
thread.Start();
@@ -92,19 +92,23 @@ public void TestThreadRm()
9292
}
9393

9494
/// <summary>
95-
/// Test that the JvmThreadGarbageCollectionInterval configuration defaults to 5 minutes,
96-
/// and can be updated correctly by setting the environment variable.
95+
/// Test that the GC interval configuration defaults to 5 minutes, and can be updated
96+
/// correctly by setting the environment variable.
9797
/// </summary>
9898
[Fact]
9999
public void TestIntervalConfiguration()
100100
{
101101
// Default value is 5 minutes.
102102
Assert.Null(Environment.GetEnvironmentVariable("DOTNET_THREAD_GC_INTERVAL"));
103-
Assert.Equal(TimeSpan.FromMinutes(5), SparkEnvironment.ConfigurationService.JvmThreadGarbageCollectionInterval);
103+
Assert.Equal(
104+
TimeSpan.FromMinutes(5),
105+
SparkEnvironment.ConfigurationService.JvmThreadGCInterval);
104106

105107
// Test a custom value.
106108
Environment.SetEnvironmentVariable("DOTNET_THREAD_GC_INTERVAL", "1:30:00");
107-
Assert.Equal(TimeSpan.FromMinutes(90), SparkEnvironment.ConfigurationService.JvmThreadGarbageCollectionInterval);
109+
Assert.Equal(
110+
TimeSpan.FromMinutes(90),
111+
SparkEnvironment.ConfigurationService.JvmThreadGCInterval);
108112
}
109113
}
110114
}

src/csharp/Microsoft.Spark/Interop/Ipc/JvmBridge.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal sealed class JvmBridge : IJvmBridge
3636
private readonly ILoggerService _logger =
3737
LoggerServiceFactory.GetLogger(typeof(JvmBridge));
3838
private readonly int _portNumber;
39-
private readonly JvmThreadPoolGarbageCollector _jvmThreadPool;
39+
private readonly JvmThreadPoolGC _jvmThreadPoolGC;
4040

4141
internal JvmBridge(int portNumber)
4242
{
@@ -48,8 +48,8 @@ internal JvmBridge(int portNumber)
4848
_portNumber = portNumber;
4949
_logger.LogInfo($"JvMBridge port is {portNumber}");
5050

51-
_jvmThreadPool = new JvmThreadPoolGarbageCollector(
52-
this, SparkEnvironment.ConfigurationService.JvmThreadGarbageCollectionInterval);
51+
_jvmThreadPoolGC = new JvmThreadPoolGC(
52+
this, SparkEnvironment.ConfigurationService.JvmThreadGCInterval);
5353
}
5454

5555
private ISocketWrapper GetConnection()
@@ -183,7 +183,7 @@ private object CallJavaMethod(
183183
(int)payloadMemoryStream.Position);
184184
outputStream.Flush();
185185

186-
_jvmThreadPool.TryAddThread(thread);
186+
_jvmThreadPoolGC.TryAddThread(thread);
187187

188188
Stream inputStream = socket.InputStream;
189189
int isMethodCallFailed = SerDe.ReadInt32(inputStream);
@@ -419,7 +419,7 @@ private object ReadCollection(Stream s)
419419

420420
public void Dispose()
421421
{
422-
_jvmThreadPool.Dispose();
422+
_jvmThreadPoolGC.Dispose();
423423
while (_sockets.TryDequeue(out ISocketWrapper socket))
424424
{
425425
if (socket != null)

src/csharp/Microsoft.Spark/Interop/Ipc/JvmThreadPoolGarbageCollector.cs renamed to src/csharp/Microsoft.Spark/Interop/Ipc/JvmThreadPoolGC.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft.Spark.Interop.Ipc
1919
/// thread is no longer alive, this class submits an rmThread command to the JVM backend to
2020
/// dispose of its corresponding JVM thread. All methods are thread-safe.
2121
/// </summary>
22-
internal class JvmThreadPoolGarbageCollector : IDisposable
22+
internal class JvmThreadPoolGC : IDisposable
2323
{
2424
private readonly IJvmBridge _jvmBridge;
2525
private readonly TimeSpan _threadGCInterval;
@@ -29,11 +29,11 @@ internal class JvmThreadPoolGarbageCollector : IDisposable
2929
private Timer _activeThreadGCTimer;
3030

3131
/// <summary>
32-
/// Construct the JvmThreadPoolGarbageCollector.
32+
/// Construct the JvmThreadPoolGC.
3333
/// </summary>
3434
/// <param name="jvmBridge">The JvmBridge used to call JVM methods.</param>
3535
/// <param name="threadGCInterval">The interval to GC finished threads.</param>
36-
public JvmThreadPoolGarbageCollector(IJvmBridge jvmBridge, TimeSpan threadGCInterval)
36+
public JvmThreadPoolGC(IJvmBridge jvmBridge, TimeSpan threadGCInterval)
3737
{
3838
_jvmBridge = jvmBridge;
3939
_threadGCInterval = threadGCInterval;
@@ -57,7 +57,7 @@ public void Dispose()
5757
}
5858
}
5959

60-
GarbageCollectThreads();
60+
GCThreads();
6161
}
6262

6363
/// <summary>
@@ -77,7 +77,7 @@ public bool TryAddThread(Thread thread)
7777
if (_activeThreadGCTimer == null && _activeThreads.Count > 0)
7878
{
7979
_activeThreadGCTimer = new Timer(
80-
(state) => GarbageCollectThreads(),
80+
(state) => GCThreads(),
8181
null,
8282
_threadGCInterval,
8383
_threadGCInterval);
@@ -112,7 +112,7 @@ private bool TryRemoveAndDisposeThread(int threadId)
112112
/// <summary>
113113
/// Remove any threads that are no longer active.
114114
/// </summary>
115-
private void GarbageCollectThreads()
115+
private void GCThreads()
116116
{
117117
foreach (KeyValuePair<int, Thread> kvp in _activeThreads)
118118
{

src/csharp/Microsoft.Spark/Services/ConfigurationService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ internal sealed class ConfigurationService : IConfigurationService
3434
private string _workerPath;
3535

3636
/// <summary>
37-
/// How often to run GC on JVM ThreadPool threads.
37+
/// How often to run GC on JVM ThreadPool threads. Defaults to 5 minutes.
3838
/// </summary>
39-
public TimeSpan JvmThreadGarbageCollectionInterval
39+
public TimeSpan JvmThreadGCInterval
4040
{
4141
get
4242
{

src/csharp/Microsoft.Spark/Services/IConfigurationService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Microsoft.Spark.Services
1212
internal interface IConfigurationService
1313
{
1414
/// <summary>
15-
/// How often to run GC on JVM ThreadPool threads. Default value is 5 minutes.
15+
/// How often to run GC on JVM ThreadPool threads.
1616
/// </summary>
17-
TimeSpan JvmThreadGarbageCollectionInterval { get; }
17+
TimeSpan JvmThreadGCInterval { get; }
1818

1919
/// <summary>
2020
/// The port number used for communicating with the .NET backend process.

0 commit comments

Comments
 (0)