The efficiency of JSON data processing.

there’re about 680M map data in JSON I was proccessing (transforme JSON String to JSONArray then write in database).I ran the program in the afternoon , when I checked next morning,it still hadn’t finished!!I do the format transformed every 20M data,but seems like it’s not very effective…so let’s find out what is the best size limit when you try to proccess a huge JSON data.
Here’s Code I’m using ,proccess a 188MB JSON file.

/**
 * <B>方法名称:</B>读取地图数据文件<BR>
 * <B>概要说明:</B>数据文件读取成List<BR>
 * 
 * @return List<JSONArray> 地图数据List
 * @throws IOException
 */
public List<JSONArray> readMapFile(MultipartFile multipartFile) throws IOException {
    List<JSONArray> mapFiles = new ArrayList<JSONArray>();
    JSONArray mapFile = new JSONArray();
    if (!multipartFile.isEmpty()) {
        StringBuffer sb = new StringBuffer();
        InputStreamReader reader = new InputStreamReader(multipartFile.getInputStream());
        BufferedReader bufferedReader = new BufferedReader(reader);
        String temp = "";
        int count = 0;
        boolean valid = false;
        while ((temp = bufferedReader.readLine()) != null) {
            sb.append(temp);
            if (!valid) {
                if (sb.indexOf("\"features\": [") == -1) {
                    continue;
                } else {
                    temp = sb.substring(sb.indexOf("\"features\": [") + 12);
                    sb.setLength(0);
                    sb.append(temp);
                    valid = true;
                }
            } else {
                if (sb.length() > 15 * 1024 * 1024) {
                    Calendar start = Calendar.getInstance();
                    temp = sb.substring(sb.lastIndexOf(",{ \"type\": \"Feature\", \"properties\":"));
                    mapFile = JSONArray.fromObject(
                            sb.substring(0, sb.lastIndexOf(",{ \"type\": \"Feature\", \"properties\":")) + "]");
                    mapFiles.add(mapFile);
                    Calendar end = Calendar.getInstance();
                    System.out.println("-------第" + (++count) + "个文件读取完毕,平均处理时间"
                            + (end.getTimeInMillis() - start.getTimeInMillis()) / 1000 + "---------------");
                    sb.setLength(0);
                    sb.append("[" + temp.substring(1));
                }
            }
        }
        bufferedReader.close();
        mapFile = JSONArray.fromObject(sb.substring(0, sb.lastIndexOf("}")));
        System.out.println("-------第" + (++count) + "个文件读取完毕,文件处理完成---------------");
        mapFiles.add(mapFile);
    }
    return mapFiles;
}

Here’s result with different data size of each transformation…

10MB
-------第1个文件读取完毕,平均处理时间7---------------
-------第2个文件读取完毕,平均处理时间6---------------
-------第3个文件读取完毕,平均处理时间8---------------
-------第4个文件读取完毕,平均处理时间11---------------
-------第5个文件读取完毕,平均处理时间6---------------
-------第6个文件读取完毕,平均处理时间8---------------
-------第7个文件读取完毕,平均处理时间10---------------
-------第8个文件读取完毕,平均处理时间6---------------
-------第9个文件读取完毕,平均处理时间6---------------
-------第10个文件读取完毕,平均处理时间9---------------
-------第11个文件读取完毕,平均处理时间7---------------
-------第12个文件读取完毕,平均处理时间7---------------
-------第13个文件读取完毕,平均处理时间14---------------
-------第14个文件读取完毕,平均处理时间6---------------
-------第15个文件读取完毕,平均处理时间13---------------
-------第16个文件读取完毕,平均处理时间17---------------
-------第17个文件读取完毕,平均处理时间14---------------
-------第18个文件读取完毕,平均处理时间7---------------
-------第18个文件读取完毕,文件处理完成---------------
-------共18个文件读取完毕,共177---------------
basically,the rate is about 1MB/s

5MB
-------第1个文件读取完毕,平均处理时间2---------------
-------第2个文件读取完毕,平均处理时间2---------------
-------第3个文件读取完毕,平均处理时间2---------------
-------第4个文件读取完毕,平均处理时间2---------------
-------第5个文件读取完毕,平均处理时间2---------------
-------第6个文件读取完毕,平均处理时间2---------------
-------第7个文件读取完毕,平均处理时间3---------------
-------第8个文件读取完毕,平均处理时间2---------------
-------第9个文件读取完毕,平均处理时间2---------------
-------第10个文件读取完毕,平均处理时间2---------------
-------第11个文件读取完毕,平均处理时间3---------------
-------第12个文件读取完毕,平均处理时间3---------------
-------第13个文件读取完毕,平均处理时间3---------------
-------第14个文件读取完毕,平均处理时间3---------------
-------第15个文件读取完毕,平均处理时间2---------------
-------第16个文件读取完毕,平均处理时间2---------------
-------第17个文件读取完毕,平均处理时间3---------------
-------第18个文件读取完毕,平均处理时间2---------------
-------第19个文件读取完毕,平均处理时间2---------------
-------第20个文件读取完毕,平均处理时间3---------------
-------第21个文件读取完毕,平均处理时间2---------------
-------第22个文件读取完毕,平均处理时间2---------------
-------第23个文件读取完毕,平均处理时间3---------------
-------第24个文件读取完毕,平均处理时间4---------------
-------第25个文件读取完毕,平均处理时间3---------------
-------第26个文件读取完毕,平均处理时间6---------------
-------第27个文件读取完毕,平均处理时间2---------------
-------第28个文件读取完毕,平均处理时间2---------------
-------第29个文件读取完毕,平均处理时间4---------------
-------第30个文件读取完毕,平均处理时间4---------------
-------第31个文件读取完毕,平均处理时间4---------------
-------第32个文件读取完毕,平均处理时间4---------------
-------第33个文件读取完毕,平均处理时间5---------------
-------第34个文件读取完毕,平均处理时间3---------------
-------第35个文件读取完毕,平均处理时间3---------------
-------第36个文件读取完毕,平均处理时间4---------------
-------第37个文件读取完毕,平均处理时间3---------------
-------第37个文件读取完毕,文件处理完成---------------
-------共37个文件读取完毕,共125---------------
the efficiency is clearly better,rate is about 1.5MB/s

-------第1个文件读取完毕,平均处理时间0---------------

-------第41个文件读取完毕,平均处理时间0---------------
-------第42个文件读取完毕,平均处理时间1---------------
-------第43个文件读取完毕,平均处理时间0---------------

-------第100个文件读取完毕,平均处理时间0---------------
-------第101个文件读取完毕,平均处理时间1---------------
-------第102个文件读取完毕,平均处理时间0---------------

-------第150个文件读取完毕,平均处理时间0---------------
-------第151个文件读取完毕,平均处理时间1---------------
-------第152个文件读取完毕,平均处理时间0---------------

-------第191个文件读取完毕,平均处理时间0---------------
-------第191个文件读取完毕,文件处理完成---------------
-------共191个文件读取完毕,共91---------------
doesn’t even use much time !!rate is like 2MB/s!

then I tried 2MB and 0.5MB,
rate were 2BM/s and 2.5MB/s.

so I guess it’s the smaller,the faster…seriously…

猜你喜欢

转载自blog.csdn.net/weixin_42540829/article/details/83303144
今日推荐