为什么我的log4j.properties文件没有被使用?(Why isn't my log4j.properties file getting used?)
我在当前目录中有一个log4j.properties文件,它指定了一些要在DEBUG级别记录的东西,以及其他所有东西作为INFO:
log4j.rootLogger=WARN, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n log4j.logger.com.xcski=DEBUG log4j.logger.org.apache.nutch.protocol.http=DEBUG log4j.logger.org.apache.nutch.fetcher.Fetcher=DEBUG
我从ant运行项目:
<target name="crawl" depends="compile"> <java classname="com.xcski.nutch.crawler.Crawler" maxmemory="1000m" fork="true"> <classpath refid="run.classpath"/> </java> </target>
但由于某种原因,我得到的唯一输出来自LOG.info(),而不是LOG.debug。 我确定这是微不足道的,但我现在已经在墙上撞了一个小时了,我以为我会尝试这样做。
I have a log4j.properties file in my current directory that specifies some things to log at DEBUG level, and everything else as INFO:
log4j.rootLogger=WARN, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n log4j.logger.com.xcski=DEBUG log4j.logger.org.apache.nutch.protocol.http=DEBUG log4j.logger.org.apache.nutch.fetcher.Fetcher=DEBUG
And I run the project from ant:
<target name="crawl" depends="compile"> <java classname="com.xcski.nutch.crawler.Crawler" maxmemory="1000m" fork="true"> <classpath refid="run.classpath"/> </java> </target>
But for some reason, the only output I get is from LOG.info(), not LOG.debug. I'm sure it's something trivial, but I've been beating my head against the wall for an hour now and I thought I'd try SO.
原文:https://stackoverflow.com/questions/1284952
最满意答案
我觉得你的记忆力很低。 这是该示例的修改版本,当您有许多任务时,它应该更好地工作。 它使用doSNOW而不是doParallel,因为doSNOW允许您在工作人员返回时使用combine函数处理结果。 此示例将这些结果写入文件以便使用更少的内存,但是它使用“.final”函数将结果读回到内存中,但如果没有足够的内存,则可以跳过该结果。
library(doSNOW) library(tcltk) nw <- 4 # number of workers cl <- makeSOCKcluster(nw) registerDoSNOW(cl) x <- iris[which(iris[,5] != 'setosa'), c(1,5)] niter <- 15e+6 chunksize <- 4000 # may require tuning for your machine maxcomb <- nw + 1 # this count includes fobj argument totaltasks <- ceiling(niter / chunksize) comb <- function(fobj, ...) { for(r in list(...)) writeBin(r, fobj) fobj } final <- function(fobj) { close(fobj) t(matrix(readBin('temp.bin', what='double', n=niter*2), nrow=2)) } mkprogress <- function(total) { pb <- tkProgressBar(max=total, label=sprintf('total tasks: %d', total)) function(n, tag) { setTkProgressBar(pb, n, label=sprintf('last completed task: %d of %d', tag, total)) } } opts <- list(progress=mkprogress(totaltasks)) resultFile <- file('temp.bin', open='wb') r <- foreach(n=idiv(niter, chunkSize=chunksize), .combine='comb', .maxcombine=maxcomb, .init=resultFile, .final=final, .inorder=FALSE, .options.snow=opts) %dopar% { do.call('c', lapply(seq_len(n), function(i) { ind <- sample(100, 100, replace=TRUE) result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit)) coefficients(result1) })) }
我包含了一个进度条,因为此示例需要几个小时才能执行。
请注意,此示例还使用
iterators
包中的idiv
函数来增加每个任务中的工作量。 这种技术称为分块 ,通常可以提高并行性能。 然而,使用idiv
任务索引,因为变量i
现在是每任务索引而不是全局索引。 对于全局索引,您可以编写一个包装idiv
的自定义迭代器:idivix <- function(n, chunkSize) { i <- 1 it <- idiv(n, chunkSize=chunkSize) nextEl <- function() { m <- nextElem(it) # may throw 'StopIterator' value <- list(i=i, m=m) i <<- i + m value } obj <- list(nextElem=nextEl) class(obj) <- c('abstractiter', 'iter') obj }
此迭代器发出的值是列表,每个列表包含起始索引和计数。 这是一个使用此自定义迭代器的简单foreach循环:
r <- foreach(a=idivix(10, chunkSize=3), .combine='c') %dopar% { do.call('c', lapply(seq(a$i, length.out=a$m), function(i) { i })) }
当然,如果任务计算量足够大,您可能不需要分块,并且可以使用原始示例中的简单foreach循环。
I think you're running low on memory. Here's a modified version of that example that should work better when you have many tasks. It uses doSNOW rather than doParallel because doSNOW allows you to process the results with the combine function as they're returned by the workers. This example writes those results to a file in order to use less memory, however it reads the results back into memory at the end using a ".final" function, but you could skip that if you don't have enough memory.
library(doSNOW) library(tcltk) nw <- 4 # number of workers cl <- makeSOCKcluster(nw) registerDoSNOW(cl) x <- iris[which(iris[,5] != 'setosa'), c(1,5)] niter <- 15e+6 chunksize <- 4000 # may require tuning for your machine maxcomb <- nw + 1 # this count includes fobj argument totaltasks <- ceiling(niter / chunksize) comb <- function(fobj, ...) { for(r in list(...)) writeBin(r, fobj) fobj } final <- function(fobj) { close(fobj) t(matrix(readBin('temp.bin', what='double', n=niter*2), nrow=2)) } mkprogress <- function(total) { pb <- tkProgressBar(max=total, label=sprintf('total tasks: %d', total)) function(n, tag) { setTkProgressBar(pb, n, label=sprintf('last completed task: %d of %d', tag, total)) } } opts <- list(progress=mkprogress(totaltasks)) resultFile <- file('temp.bin', open='wb') r <- foreach(n=idiv(niter, chunkSize=chunksize), .combine='comb', .maxcombine=maxcomb, .init=resultFile, .final=final, .inorder=FALSE, .options.snow=opts) %dopar% { do.call('c', lapply(seq_len(n), function(i) { ind <- sample(100, 100, replace=TRUE) result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit)) coefficients(result1) })) }
I included a progress bar since this example takes several hours to execute.
Note that this example also uses the
idiv
function from theiterators
package to increase the amount of work in each of the tasks. This technique is called chunking, and often improves the parallel performance. However, usingidiv
messes up the task indices, since the variablei
is now a per-task index rather than a global index. For a global index, you can write a custom iterator that wrapsidiv
:idivix <- function(n, chunkSize) { i <- 1 it <- idiv(n, chunkSize=chunkSize) nextEl <- function() { m <- nextElem(it) # may throw 'StopIterator' value <- list(i=i, m=m) i <<- i + m value } obj <- list(nextElem=nextEl) class(obj) <- c('abstractiter', 'iter') obj }
The values emitted by this iterator are lists, each containing a starting index and a count. Here's a simple foreach loop that uses this custom iterator:
r <- foreach(a=idivix(10, chunkSize=3), .combine='c') %dopar% { do.call('c', lapply(seq(a$i, length.out=a$m), function(i) { i })) }
Of course, if the tasks are compute intensive enough, you may not need chunking and can use a simple foreach loop as in the original example.
相关问答
更多-
byrow = F旁边有一个“)”,即 foreach(i=1:6,.combine=matrix(0,6,5,byrow=F)) %dopar% Mat.corr[i,]=cop.theta(index,EXPR,QT=survp[,i]) 应该修复此错误。 但是,请注意, foreach循环内的mat.corr[i,]=...不会将cop.theta操作产生的值写入此特定行,只要您并行运行循环 - 这只是可以使用单核foreach 。 这意味着,您必须使用foreach()内部的.combine或 ...
-
好吧,我想通过调用foreach和%dopar%得到它: # Libraries --------------------------------------------------------------- if (!require("pacman")) install.packages("pacman") pacman::p_load(lakemorpho,rgdal,maptools,sp,doParallel,foreach, doParallel) # Data - ...
-
问题很可能是您没有为每个工作者调用library(xts) 。 你不会说你使用的后端,所以我不能100%确定。 如果这是问题,那么这段代码将修复它: list <- foreach(i=1:ncol(combs)) %dopar% { library(xts) tmp_triple <- combs[,i] p1<-data[tmp_triple[[1]]][[1]] p2<-data[tmp_triple[[2]]][[1]] p3<-data[tmp_tripl ...
-
我同意问题是由于停止了主控并继续使用处于损坏状态的集群对象造成的。 在与群集工作人员的套接字连接中可能存在未读数据,导致主人和工作人员不同步。 您甚至可能在调用stopCluster遇到问题,因为它也会写入套接字连接。 如果您确实停止了主设备,我会建议调用stopCluster然后创建另一个集群对象,但请记住,以前的工作人员可能无法始终正常退出。 最好验证工作进程是否已经死亡,如果不是,则手动杀死它们。 I agree that the problem was caused by stopping the ...
-
您需要注册一个并行后端。 做类似的事情 library(doParallel) registerDoParallel(cores=4) You need to register a parallel backend. Do something like library(doParallel) registerDoParallel(cores=4)
-
doParallel(包)foreach不适用于R中的大迭代(doParallel (package) foreach does not work for big iterations in R)[2023-09-17]
我觉得你的记忆力很低。 这是该示例的修改版本,当您有许多任务时,它应该更好地工作。 它使用doSNOW而不是doParallel,因为doSNOW允许您在工作人员返回时使用combine函数处理结果。 此示例将这些结果写入文件以便使用更少的内存,但是它使用“.final”函数将结果读回到内存中,但如果没有足够的内存,则可以跳过该结果。 library(doSNOW) library(tcltk) nw <- 4 # number of workers cl <- makeSOCKcluster(nw) r ... -
在GPU上预测多普勒并行(foreach doparallel on GPU)[2022-04-12]
使用foreach或类似工具进行并行化是有效的,因为您有多个CPU(或具有多个内核的CPU),可以同时处理多个任务。 GPU也有多个核心,但这些核心已经用于并行处理单个任务 。 因此,如果您想进一步并行化,则需要多个GPU 。 但是,请记住,GPU仅比某些类型的应用程序更快。 使用大型矩阵的矩阵运算就是一个很好的例子! 有关一个特定示例的最新比较,请参见此处的性能部分。 因此,您可以考虑GPU是否适合您。 此外:文件IO将始终通过CPU。 Parallelization with foreach or si ... -
因此,我们可以调用“您正在迭代的事物的数量”,您可以为不同的进程动态设置它们 编写并行化脚本可能看起来像这样 if(length(iter)==1){ Result <- #some function } else { cl <- makeCluster(iter) registerDoParallel(cl) Result <- foreach(z=1:iter) %dopar% { # some function } stopCluster(cl) } 如果iter为 ...
-
R - doParallel不适用于Student和Fisher测试(R - doParallel does not work with Student and Fisher tests)[2023-07-18]
我无法重现你的问题。 这对我来说很好: matrixA <- matrix(runif(36), 6) matrixB <- matrix(runif(36), 6) cl <- parallel::makeCluster(4) doParallel::registerDoParallel(cl) library(foreach) p.values.res<-foreach(i=seq(dim(matrixA)[1])) %dopar% var.test(matrixA[i,],matrixB[i,] ... -
大foreach循环变慢(big foreach loop getting slower)[2023-09-23]
我注意到的一件坏事是你附加了param字符串变量。 这将在您的循环中创建大量扔掉的对象。 而是使用字符串生成器。 StringBuilder builder = new StringBuilder() foreach (Busqueda.CodDesCIE elemResult in result.listaCodDesCIE) { .. builder.Append(" IdBuzon_Detalle:").Append( elemResultExterno.IdBuzonDetalle); ...