Skip to content

Conversation

@infynyxx
Copy link
Contributor

@infynyxx infynyxx commented Jun 22, 2016

What changes were proposed in this pull request?

Initialize logger instance lazily in Scala preferred way

How was this patch tested?

By running ./build/mvn clean test locally

}
log_
}
protected def log: Logger = log_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need log_ separately from log? log can now be the lazy val.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In class DriverEndpoint under CoarseGrainedSchedulerBackend.scala,
log() seems to be overridden[1]

Not sure, what's the logic behind that but if we can remove that, log()
can also be removed from Logging trait.

[1]
https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/scheduler/cluster/CoarseGrainedSchedulerBackend.scala#L103

On Wed, Jun 22, 2016 at 12:48 PM, Sean Owen notifications@github.com
wrote:

In core/src/main/scala/org/apache/spark/internal/Logging.scala
#13842 (comment):

@@ -41,13 +44,7 @@ private[spark] trait Logging {
}

// Method to get or create the logger for this object

  • protected def log: Logger = {
  • if (log_ == null) {
  •  initializeLogIfNecessary(false)
    
  •  log_ = LoggerFactory.getLogger(logName)
    
  • }
  • log_
  • }
  • protected def log: Logger = log_

Do we even need log_ separately from log? log can now be the lazy val.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/apache/spark/pull/13842/files/88ffc87c670deb675f443891a4b2e3315467098e#r68046045,
or mute the thread
https://github.com/notifications/unsubscribe/AACdKruY8xLoqhQEkqS167NIyEM-v4Qtks5qOS8lgaJpZM4I7vOl
.

Cheers,
Praj

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think that can be removed. I don't see the point of it, as neither it nor its subclass even logs anything directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed via
infynyxx@986e61f

On Wed, Jun 22, 2016 at 2:17 PM, Sean Owen notifications@github.com wrote:

In core/src/main/scala/org/apache/spark/internal/Logging.scala
#13842 (comment):

@@ -41,13 +44,7 @@ private[spark] trait Logging {
}

// Method to get or create the logger for this object

  • protected def log: Logger = {
  • if (log_ == null) {
  •  initializeLogIfNecessary(false)
    
  •  log_ = LoggerFactory.getLogger(logName)
    
  • }
  • log_
  • }
  • protected def log: Logger = log_

Good point. I think that can be removed. I don't see the point of it, as
neither it nor its subclass even logs anything directly?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/apache/spark/pull/13842/files/88ffc87c670deb675f443891a4b2e3315467098e#r68060626,
or mute the thread
https://github.com/notifications/unsubscribe/AACdKnkKjiFYLhaEMT3wJslNc4olwNSKks5qOUPtgaJpZM4I7vOl
.

Cheers,
Praj

// Make the log field transient so that objects with Logging can
// be serialized and used on another machine
@transient private var log_ : Logger = null
@transient lazy val log : Logger = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will fail style checks because of the space before the colon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, my bad. Fixed via
infynyxx@18ae8c5

On Wed, Jun 22, 2016 at 3:15 PM, Sean Owen notifications@github.com wrote:

In core/src/main/scala/org/apache/spark/internal/Logging.scala
#13842 (comment):

@@ -32,23 +32,17 @@ private[spark] trait Logging {

// Make the log field transient so that objects with Logging can
// be serialized and used on another machine

I think this will fail style checks because of the space before the colon


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/apache/spark/pull/13842/files/986e61f96ece6d7f71ff760384cc7553fe3828f4#r68072052,
or mute the thread
https://github.com/notifications/unsubscribe/AACdKtAjTKSCyAI2oyyH7fFUatd4xsCmks5qOVGUgaJpZM4I7vOl
.

Cheers,
Praj

@srowen
Copy link
Member

srowen commented Jun 22, 2016

Jenkins test this please

@SparkQA
Copy link

SparkQA commented Jun 22, 2016

Test build #61040 has finished for PR 13842 at commit 986e61f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen
Copy link
Member

srowen commented Jun 22, 2016

Jenkins retest this please

@SparkQA
Copy link

SparkQA commented Jun 22, 2016

Test build #61047 has finished for PR 13842 at commit 18ae8c5.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

// Make the log field transient so that objects with Logging can
// be serialized and used on another machine
@transient private var log_ : Logger = null
@transient lazy val log: Logger = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lazy will add a volatile flag to log and prevents some JIT optimizations?

@zsxwing
Copy link
Member

zsxwing commented Jun 22, 2016

So the pros is only calling initializeLogIfNecessary(false) and LoggerFactory.getLogger(logName) once, the cons is marking a field used frequently volatile. I don't think it's worth.

@srowen
Copy link
Member

srowen commented Jun 22, 2016

Well, it simplifies the code too and avoids a method call. The current variable really ought to be volatile but isn't, so I don't know if that's a downside. I think the performance issue is negligible, since the cost of dereferencing a volatile variable is nothing compared to the time to construct and log the message to disk. It's really minor but I think there are only upsides here.

@zsxwing
Copy link
Member

zsxwing commented Jun 22, 2016

I was thinking about logTrace and logDebug. They are not enabled so the cost of them are cheaper comparing dereferencing a volatile variable. Anyway, in a second thought, we should remove a a debug/trace log if we are concerned about the performance instead of counting on logs are cheap.

So 👍

@zsxwing
Copy link
Member

zsxwing commented Jun 22, 2016

retest this please

@SparkQA
Copy link

SparkQA commented Jun 22, 2016

Test build #61065 has finished for PR 13842 at commit 18ae8c5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@zsxwing
Copy link
Member

zsxwing commented Jun 22, 2016

Thanks. Merging to master and 2.0!

asfgit pushed a commit that referenced this pull request Jun 22, 2016
## What changes were proposed in this pull request?

Initialize logger instance lazily in Scala preferred way

## How was this patch tested?

By running `./build/mvn clean test` locally

Author: Prajwal Tuladhar <praj@infynyxx.com>

Closes #13842 from infynyxx/spark_internal_logger.

(cherry picked from commit 044971e)
Signed-off-by: Shixiong Zhu <shixiong@databricks.com>
@asfgit asfgit closed this in 044971e Jun 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants