zoukankan      html  css  js  c++  java
  • 关于JSON的大文本处理

    JSON在处理大文本数据的时候存在严重的效率问题,反序列化的时候CPU占用率甚至可以达到80%,
    找到个处理办法是在客户端就拆成小片段,到服务器再组装起来,如下:
     1//大文本优化
     2                var originContent = article.Content;                
     3                var contentLen = originContent.length;
     4                if(contentLen > 1000){
     5                    article.Content = '';        //clear it!!!
     6                    var len = Math.ceil(contentLen / 1000);
     7                    var splitContent = [];
     8                    for(var i=0;i < len; i++){
     9                        var start = i*1000;
    10                        var end = start + 1000;
    11                        if(end > contentLen-1) end = contentLen -1;
    12                        splitContent.push(originContent.substring(start,end));
    13                    }

    14                    article.ContentSegments = splitContent;
    15                }

    然后在服务器端组装起来:
     1if(article.Content.Length == 0)
     2            {
     3                if(article.ContentSegments != null && article.ContentSegments.Count > 0)
     4                {
     5                    StringBuilder buf = new StringBuilder();
     6                    foreach (string s in article.ContentSegments)
     7                    {
     8                        buf.Append(s);
     9                    }

    10                    article.Content = buf.ToString();
    11                }

    12            }



  • 相关阅读:
    JS 格林威治时间格式(GMT)格式化
    SQL Server各个版本功能比较
    SQL Server各个版本功能比较
    SQL Server各个版本功能比较
    SQLl中的left join、right join、inner join详解
    SQLl中的left join、right join、inner join详解
    SQLl中的left join、right join、inner join详解
    【必备】jQuery性能优化的38个建议
    Metasploit笔记
    SpringBoot开发二十-Redis入门以及Spring整合Redis
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/1009862.html
Copyright © 2011-2022 走看看