Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High concurrency, stanfordnlp out of memory error. #1461

Open
Paper-Heart opened this issue Aug 14, 2024 · 5 comments
Open

High concurrency, stanfordnlp out of memory error. #1461

Paper-Heart opened this issue Aug 14, 2024 · 5 comments

Comments

@Paper-Heart
Copy link

Paper-Heart commented Aug 14, 2024

Current Circumstances:
I've integrated the stanford ner functionality into a java service that has tens of millions of calls per day. I deployed in 3 clusters and allocated 10GB of memory per pod.

Issue:
Over a period of about seven days, Pods not available and continued to report OutOfMemory Exceptions.

Calling Code:

    private static final Log LOG = LogFactory.getInstance(StanfordNlpApp.class);

    private static StanfordCoreNLP pipeline;

    //executed once on system start
    public static void initNLP() {
        pipeline = new StanfordCoreNLP("stanford-hanweb-chinese.properties");
    }

    public static List<NerEntityBean> nerByText(String text) {
        List<NerEntityBean> nerEntityBeans = new ArrayList<>();
        long startTime = System.currentTimeMillis();
        Annotation document = new Annotation(text);
        pipeline.annotate(document);
        List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
        for (CoreMap sentence : sentences) {
            for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
                String ner = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
                int pos = token.beginPosition();
                if (StringUtil.equals(ner, "O")) {
                    continue;
                }
                String word = token.get(CoreAnnotations.TextAnnotation.class);
                NerEntityBean nerEntityBean = new NerEntityBean();
                nerEntityBean.setPos(pos);
                nerEntityBean.setWord(word);
                nerEntityBean.setType(ner);
                nerEntityBeans.add(nerEntityBean);
            }
        }
        long endTime = System.currentTimeMillis();
        long costTime = endTime - startTime;
        LOG.debug("StanfordNlp cost : " + costTime);
        return nerEntityBeans;
    }

Configuration File:

# Pipeline options - lemma is no-op for Chinese but currently needed because coref demands it (bad old requirements system)
annotators = tokenize, ssplit, pos, lemma, ner, parse, coref

# segment
tokenize.language = zh
segment.model = edu/stanford/nlp/models/segmenter/chinese/ctb.gz
segment.sighanCorporaDict = edu/stanford/nlp/models/segmenter/chinese
segment.serDictionary = edu/stanford/nlp/models/segmenter/chinese/dict-chris6.ser.gz,data/model/name-dict.ser.gz
segment.sighanPostProcessing = true

# sentence split
ssplit.boundaryTokenRegex = [.?]|[!???]+

# pos
pos.model = edu/stanford/nlp/models/pos-tagger/chinese-distsim.tagger

# ner
ner.language = chinese
ner.model = edu/stanford/nlp/models/ner/chinese.misc.distsim.crf.ser.gz
ner.applyNumericClassifiers = true
ner.useSUTime = false

# regexner
ner.fine.regexner.mapping = edu/stanford/nlp/models/kbp/chinese/gazetteers/cn_regexner_mapping.tab
ner.fine.regexner.noDefaultOverwriteLabels = CITY,COUNTRY,STATE_OR_PROVINCE

# parse
parse.model = edu/stanford/nlp/models/srparser/chineseSR.ser.gz

# depparse
depparse.model    = edu/stanford/nlp/models/parser/nndep/UD_Chinese.gz
depparse.language = chinese

# coref
coref.sieves = ChineseHeadMatch, ExactStringMatch, PreciseConstructs, StrictHeadMatch1, StrictHeadMatch2, StrictHeadMatch3, StrictHeadMatch4, PronounMatch
coref.input.type = raw
coref.postprocessing = true
coref.calculateFeatureImportance = false
coref.useConstituencyTree = true
coref.useSemantics = false
coref.algorithm = hybrid
coref.path.word2vec =
coref.language = zh
coref.defaultPronounAgreement = true
coref.zh.dict = edu/stanford/nlp/models/dcoref/zh-attributes.txt.gz
coref.print.md.log = false
coref.md.type = RULE
coref.md.liberalChineseMD = false

# kbp
kbp.semgrex = edu/stanford/nlp/models/kbp/chinese/semgrex
kbp.tokensregex = edu/stanford/nlp/models/kbp/chinese/tokensregex
kbp.language = zh
kbp.model = none

# entitylink
entitylink.wikidict = edu/stanford/nlp/models/kbp/chinese/wikidict_chinese.tsv.gz

Error Log:
image

image

Call method should have no problem. In theory, memory should be cleaned by the GC and no more than 10GB of memory should be consumed. Can help solve the out of memory problem.Thanks a lot.

@AngledLuffa
Copy link
Contributor

AngledLuffa commented Aug 14, 2024 via email

@Paper-Heart
Copy link
Author

We use java services to provide functionality, do you mean to print out the jstack information and send it to you after we serve out of memory?

@AngledLuffa
Copy link
Contributor

AngledLuffa commented Aug 15, 2024 via email

@Paper-Heart
Copy link
Author

Paper-Heart commented Aug 15, 2024

Is the heap profile a tool that is used to monitor the heap, or something else.I haven't used this tool before, perhaps you could give me a brief introduction on how to use it to help you deal with this problem.

Today, I looked at the error log of the service and found a new problem causing stackoverflow. It's not a common occurrence, and it only happened three times during the day.
The attached txt file is the log information.
error_log.txt

This kind of error, whether because some special circumstances cause the code infinite recursion.I tried several scenarios and performed pressure tests in a local environment and did not reproduce the problem.
Hope to get your reply,thanks.

AngledLuffa added a commit that referenced this issue Aug 15, 2024
…stead, just loop until the vertexIterator is used up. Observed in #1461
@AngledLuffa
Copy link
Contributor

That other error must have been a very unusual sentence. I can change it so there isn't a recursive call, but rather it iterates over the nodes in a loop.

As for the heap profile, it looks like some of the tools I used to use are no longer shipped with recent versions of Java. I'll have to investigate another way of debugging the current heap state of the server.

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

No branches or pull requests

2 participants