清明刚过,该来学习点新的知识点了。

上次说到关于MapReduce对于文本中词频的统计使用WordCount。如果还有同学不熟悉的可以参考博文大数据系列之分布式计算批处理引擎MapReduce实践

博文发表后很多同学私下反映对于MapReduce的处理原理没有了解到。在这篇博文中楼主与大家交流下MapReduce的数据处理原理及MR中各角色的职责。

文末还有示例代码讲解。。

1.MapReduce中的数据流动

  • 最简单的过程: map - reduce
  • 定制了partitioner以将map的结果送往指定reducer的过程: map - partition - reduce
  • 增加了在本地先进行一次reduce(优化)的过程: map - combine - partition - reduce

2.Partition的概念和使用

得到map产生的记录后,他们该分配给哪些reducer来处理呢?hadoop默认是根据散列值来派发,但是实际中,这并不能很高效或者按照我们要求的去执行任务。例如,经过partition处理后,一个节点的reducer分配到了20条记录,另一个却分配到了10W万条,试想,这种情况效率如何。又或者,我们想要处理后得到的文件按照一定的规律进行输出,假设有两个reducer,我们想要最终结果中part-00000中存储的是”h”开头的记录的结果,part-00001中存储其他开头的结果,这些默认的partitioner是做不到的。所以需要我们自己定制partition来选择reducer。自定义partitioner很简单,只要自定义一个类,并且继承Partitioner类,重写其getPartition方法就好了,在使用的时候通过调用Job的setPartitionerClass指定一下即可。

3.MapReduce基于key的全排序的原理

如何使用mapreduce来做全排序?最简单的方法就是使用一个partition,因为一个partition对应一个reduce的task,然而reduce的输入本来就是对key有序的,所以很自然地就产生了一个全排序文件。但是这种方法在处理大型文件时效率极低,因为一台机器必须处理所有输出文件,从而完全丧失了mapreduce所提供的并行架构的优势。

如果是分多个partition呢,则只要确保partition是有序的就行了。首先创建一系列排好序的文件;其次,串联这些文件(类似于归并排序);最后得到一个全局有序的文件。比如有1000个1-10000的数据,跑10个ruduce任务,如果进行partition的时候,能够将在1-1000中数据的分配到第一个reduce中,1001-2000的数据分配到第二个reduce中,以此类推。即第n个reduce所分配到的数据全部大于第n-1个reduce中的数据。这样,每个reduce出来之后都是有序的了,我们只要concat所有的输出文件,变成一个大的文件,就都是有序的了。

这时候可能会有一个疑问,虽然各个reduce的数据是按照区间排列好的,但是每个reduce里面的数据是乱序的啊?当然不会,不要忘了排序是MapReduce的天然特性 — 在数据达到reducer之前,mapreduce框架已经对这些数据按key排序了。

但是这里又有另外一个问题,就是在定义每个partition的边界的时候,可能会导致每个partition上分配到的记录数相差很大,这样数据最多的partition就会拖慢整个系统。我们期望的是每个partition上分配的数据量基本相同,hadoop提供了采样器帮我们预估整个边界,以使数据的分配尽量平均。

在Hadoop中,patition我们可以用TotalOrderPartitioner替换默认的分区,然后将采样的结果传给他,就可以实现我们想要的分区。在采样时,可以使用hadoop的几种采样工具,如RandomSampler,InputSampler,IntervalSampler。

关于上述过程,在《Hadoop权威指南》中有具体的讲解,其中一张图可以帮助我们更好地理解在排序操作中hadoop在map和reduce阶段所做的事:

以上文字取自网上某些博文内容。。仅供参考。。。

4.下面介绍下一个代码示例。

  1. MapReduceExample
  2.  
  3. 一组数据按照年龄分区,区内按照成绩倒序排序
  4. #数据内容见data/person.csv,如下
  5. #编号,姓名,年龄,性别,成绩
  6. 1,Alice,23,female,45
  7. 2,Bob,34,male,89
  8. 3,Chris,67,male,97
  9. 4,Kristine,38,female,53
  10. 5,Connor,25,male,27
  11. 6,Daniel,78,male,95
  12. 7,James,34,male,79
  13. 8,Alex,52,male,69
  14. 9,Nancy,7,female,98
  15. 10,Adam,9,male,37
  16. 11,Jacob,7,male,23
  17. 12,Mary,6,female,93
  18. 13,Clara,87,female,72
  19. 14,Monica,56,female,92
  20. #项目要求#
  21. 1.将数据按照年龄段分区
  22. 020岁为第一区,
  23. 2050岁为第二区,
  24. 50以上为第三区。
  25. 2.将各区的数据按照分数倒序排序输出
  26. #输出结果如下#
  27. 分区1part-r-00000
  28. 9,Nancy,female,7 98
  29. 12,Mary,female,6 93
  30. 10,Adam,male,9 37
  31. 11,Jacob,male,7 23
  32. 分区2part-r-00001
  33. 2,Bob,male,34 89
  34. 7,James,male,34 79
  35. 4,Kristine,female,38 53
  36. 1,Alice,female,23 45
  37. 5,Connor,male,25 27
  38. 分区3part-r-00002
  39. 3,Chris,male,67 97
  40. 6,Daniel,male,78 95
  41. 14,Monica,female,56 92
  42. 13,Clara,female,87 72
  43. 8,Alex,male,52 69

  4.1 解决思路

  描述一下MapReduce处理数据的大概简单流程:首先,MapReduce框架通过getSplit方法实现对原始文件的切片之后,每一个切片对应着一个map task,inputSplit输入到Map函数进行处理,中间结果经过环形缓冲区的排序compareTo(T),然后分区、自定义二次排序(如果有的话)和合并,再通过shuffle操作将数据传输到reduce task端,reduce端也存在着缓冲区,数据也会在缓冲区和磁盘中进行合并排序等操作,然后对数据按照Key值进行分组,然后每次处理完一个分组之后就会去调用一次reduce函数,最终输出结果。

   4.2 具体解决思路

    A.Map端处理:单行数据拆分,对于拆分后的数据按成绩分数进行排序,MapReduce框架不管是默认排序或者是自定义排序都只是对Key值进行排序,现在的情况是这些数据不是key值,怎么办?其实我们可以将原始数据的Key值和其对应的数据组合成一个新的Key值,然后新的Key值对应的还是之前的数字。那么我们就可以将原始数据的map输出变成类似下面的数据结构:

  1. {[1,Alice,23,female], 45}
  2. {[2,Bob,34,male], 89}
  3. {[3,Chris,67,male], 97}
  4. {[4,Kristine,38,female],53}
  5. {[5,Connor,25,male],27}
  6. {[6,Daniel,78,male],95}
  7. {[7,James,34,male],79}
  8. {[8,Alex,52,male],69}
  9. {[9,Nancy,7,female],98}
  10. {[10,Adam,9,male],37}
  11. {[11,Jacob,7,male],23}
  12. {[12,Mary,6,female],93}
  13. {[13,Clara,87,female],72}
  14. {[14,Monica,56,female],92}

   B.Partition分区操作:项目要求按照年龄进行分区,这里我们需要自定义一个分区处理器,因为我的目标不是想将所有的数据传到同一个reduce中,而是想将年龄分区后的数据放在同一个reduce中进行分组合并,所以我们需要根据新key值中的第三个字段来自定义一个分区处理器。通过分区操作后,得到的数据流如下:    

  1. partition1: 0~20
  2. {[9,Nancy,7,female],98}
  3. {[10,Adam,9,male],37}
  4. {[11,Jacob,7,male],23}
  5. {[12,Mary,6,female],93}
  6.  
  7. partition2:20~50
  8. {[1,Alice,23,female], 45}
  9. {[2,Bob,34,male], 89}
  10. {[4,Kristine,38,female],53}
  11. {[5,Connor,25,male],27}
  12. {[7,James,34,male],79}
  13.  
  14. partition3:50~
  15. {[3,Chris,67,male], 97}
  16. {[6,Daniel,78,male],95}
  17. {[8,Alex,52,male],69}
  18. {[13,Clara,87,female],72}
  19. {[14,Monica,56,female],92}

  C.自定义排序操作:分区操作完成之后,我调用自己的自定义排序器对新的Key值按照成绩分数进行排序。 排序后的数据流结果如下:

  1. partition1: 0~20
  2. {[9,Nancy,7,female],98}
  3. {[12,Mary,6,female],93}
  4. {[10,Adam,9,male],37}
  5. {[11,Jacob,7,male],23}
  6.  
  7. partition2:20~50
  8. {[2,Bob,34,male], 89}
  9. {[7,James,34,male],79}
  10. {[4,Kristine,38,female],53}
  11. {[1,Alice,23,female], 45}
  12. {[5,Connor,25,male],27}
  13.  
  14. partition3:50~
  15. {[3,Chris,67,male], 97}
  16. {[6,Daniel,78,male],95}
  17. {[14,Monica,56,female],92}
  18. {[13,Clara,87,female],72}
  19. {[8,Alex,52,male],69}

  D.Reducer操作:经过Shuffle处理之后,数据传输到Reducer端输出。

  4.2 代码

   A.代码结构如下

  pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.</modelVersion>
  6.  
  7. <groupId>mapReduceDemo</groupId>
  8. <artifactId>mapReduceDemo</artifactId>
  9. <version>1.0-SNAPSHOT</version>
  10.  
  11. <repositories>
  12. <repository>
  13. <id>nexus-aliyun</id>
  14. <name>Nexus aliyun</name>
  15. <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  16. </repository>
  17. </repositories>
  18.  
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.apache.hadoop</groupId>
  22. <artifactId>hadoop-yarn-client</artifactId>
  23. <version>2.7.</version>
  24. </dependency>
  25. <dependency>
  26. <groupId>org.apache.hadoop</groupId>
  27. <artifactId>hadoop-common</artifactId>
  28. <version>2.7.</version>
  29. </dependency>
  30. <dependency>
  31. <groupId>org.apache.hadoop</groupId>
  32. <artifactId>hadoop-mapreduce-client-jobclient</artifactId>
  33. <version>2.7.</version>
  34. </dependency>
  35. </dependencies>
  36.  
  37. <build>
  38. <plugins>
  39. <plugin>
  40. <groupId>org.apache.maven.plugins</groupId>
  41. <artifactId>maven-dependency-plugin</artifactId>
  42. <executions>
  43. <execution>
  44. <id>copy-dependencies</id>
  45. <phase>package</phase>
  46. <goals>
  47. <goal>copy-dependencies</goal>
  48. </goals>
  49. <configuration>
  50. <excludeScope>provided</excludeScope>
  51. <outputDirectory>${project.build.directory}/lib</outputDirectory>
  52. </configuration>
  53. </execution>
  54. </executions>
  55. </plugin>
  56. </plugins>
  57. </build>
  58. </project>

  B.Main.java  入口

  1. package com.m.mr;
  2.  
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.conf.Configured;
  5. import org.apache.hadoop.fs.FileSystem;
  6. import org.apache.hadoop.fs.Path;
  7. import org.apache.hadoop.io.IntWritable;
  8. import org.apache.hadoop.io.Text;
  9. import org.apache.hadoop.mapreduce.Job;
  10. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  11. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  12. import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
  13. import org.apache.hadoop.util.Tool;
  14. import org.apache.hadoop.util.ToolRunner;
  15.  
  16. /**
  17. * 操作person.csv文件
  18. */
  19. public class Main extends Configured implements Tool {
  20.  
  21. public int run(String[] args) throws Exception {
  22. if (args.length != ) {
  23. System.err.println("Usage: AgePartition <input> <output>");
  24. ToolRunner.printGenericCommandUsage(System.out);
  25. System.exit();
  26. }
  27.  
  28. Configuration conf = getConf();
  29. //conf.set(RegexMapper.GROUP,"female");
  30. Job job = Job.getInstance(conf);
  31.  
  32. FileInputFormat.addInputPath(job, new Path(args[]));
  33. Path output = new Path(args[]);
  34. FileSystem fs = FileSystem.get(conf);
  35. if (fs.exists(output)) {
  36. fs.delete(output, true);
  37. }
  38. FileOutputFormat.setOutputPath(job, output);
  39. job.setJarByClass(Main.class);
  40. job.setMapperClass(DefinedMap.class);
  41. //设置map的输出key和value类型
  42. job.setMapOutputKeyClass(DefinedCombinationKey.class);
  43. job.setMapOutputValueClass(IntWritable.class);
  44. job.setReducerClass(DefinedReducer.class);
  45. //设置reduce的输出key和value类型
  46. job.setOutputKeyClass(Text.class);
  47. job.setOutputValueClass(Text.class);
  48. //自定义分区策略
  49. job.setPartitionerClass(DefinedPartitioner.class);
  50. //自定义排序策略,在自定义组合键重写方法compareTo时若自定义排序策略与之相同可以省略自定义排序策略。最终结果以自定义排序策略为主
  51. job.setSortComparatorClass(DefinedSort.class);
  52. job.setOutputFormatClass(TextOutputFormat.class);
  53. job.setNumReduceTasks();//reducer num = partition num
  54.  
  55. return job.waitForCompletion(true) ? : ;
  56. }
  57.  
  58. public static void main(String[] args) throws Exception {
  59. int res = ToolRunner.run(new Configuration(), new Main(), args);
  60. System.exit(res);
  61. }
  62. }

  C. DefinedMap.java  {自定义分区器 class DefinedPartitioner,class Map, class Reducer}

  1. package com.m.mr;
  2.  
  3. import org.apache.hadoop.io.IntWritable;
  4. import org.apache.hadoop.io.Text;
  5. import org.apache.hadoop.mapreduce.Mapper;
  6. import org.apache.hadoop.mapreduce.Partitioner;
  7. import org.apache.hadoop.mapreduce.Reducer;
  8.  
  9. import java.io.IOException;
  10. import java.util.Iterator;
  11.  
  12. /**
  13. * @author mengfanzhu
  14. * @Package com.m.mr
  15. * @Description: 自定义 map处理
  16. * @date 17/4/7 14:04
  17. */
  18. public class DefinedMap extends Mapper<Object, Text, DefinedCombinationKey, IntWritable> {
  19. DefinedCombinationKey combinationKey=new DefinedCombinationKey();
  20. Text sortName = new Text();
  21. IntWritable score = new IntWritable();
  22.  
  23. @Override
  24. public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
  25. // no,name, age, gender, score
  26. String[] arr = value.toString().split(",");
  27. score.set(Integer.parseInt(arr[]));
  28. sortName.set(arr[]+","+arr[]+","+arr[]+","+arr[]);
  29. combinationKey.setFirstKey(sortName);
  30. combinationKey.setSecondKey(score);
  31. context.write(combinationKey, score);
  32. }
  33. }
  34.  
  35. /**
  36. * 自定义分区 按照年龄段分区
  37. */
  38. class DefinedPartitioner extends Partitioner<DefinedCombinationKey,IntWritable> {
  39. @Override
  40. public int getPartition(DefinedCombinationKey key, IntWritable value, int n) {
  41. if (n == ) {
  42. return ;
  43. }
  44. String[] arr = key.getFirstKey().toString().split(",");
  45. int age = Integer.parseInt(arr[]);
  46. if (age <= ) {
  47. return ;
  48. } else if (age <= ) {
  49. return % n;
  50. } else {
  51. return % n;
  52. }
  53. }
  54. }
  55. /**
  56. * 自定义reducer处理
  57. */
  58. class DefinedReducer extends Reducer<DefinedCombinationKey, IntWritable, Text, Text> {
  59.  
  60. StringBuffer sb=new StringBuffer();
  61. Text sore=new Text();
  62.  
  63. @Override
  64. protected void reduce(DefinedCombinationKey key, Iterable<IntWritable> values, Context context)
  65. throws IOException, InterruptedException {
  66. sb.delete(, sb.length());
  67. Iterator<IntWritable> it=values.iterator();
  68.  
  69. while (it.hasNext()) {
  70. sb.append(it.next()+",");
  71. }
  72.  
  73. if (sb.length()>) {
  74. sb.deleteCharAt(sb.length()-);
  75. }
  76. sore.set(sb.toString());
  77. context.write(key.getFirstKey(),sore);
  78. }
  79. }

    D . 自定义二次排序策略 DefinedSort

  1. package com.m.mr;
  2.  
  3. import org.apache.hadoop.io.WritableComparable;
  4. import org.apache.hadoop.io.WritableComparator;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7.  
  8. /**
  9. * @author mengfanzhu
  10. * @Description: 自定义排序策略
  11. * @date 17/4/7 13:04
  12. */
  13. public class DefinedSort extends WritableComparator {
  14. private static final Logger logger = LoggerFactory.getLogger(DefinedSort.class);
  15. public DefinedSort() {
  16. super(DefinedCombinationKey.class,true);
  17. }
  18. @Override
  19. public int compare(WritableComparable combinationKeyOne,
  20. WritableComparable CombinationKeyOther) {
  21. logger.info("---------enter DefinedComparator flag---------");
  22.  
  23. DefinedCombinationKey c1 = (DefinedCombinationKey) combinationKeyOne;
  24. DefinedCombinationKey c2 = (DefinedCombinationKey) CombinationKeyOther;
  25.  
  26. logger.info("---------out DefinedComparator flag---------");
  27. return c2.getSecondKey().get()-c1.getSecondKey().get();//0,负数,正数
  28. }
  29. }

  E.  DefinedCombinationKey.java 自定义组合键

  1. package com.m.mr;
  2.  
  3. import org.apache.hadoop.io.IntWritable;
  4. import org.apache.hadoop.io.Text;
  5. import org.apache.hadoop.io.WritableComparable;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8.  
  9. import java.io.DataInput;
  10. import java.io.DataOutput;
  11. import java.io.IOException;
  12.  
  13. /**
  14. * @author mengfanzhu
  15. * @Description:
  16. * @date 17/4/7 13:01
  17. */
  18. public class DefinedCombinationKey implements WritableComparable<DefinedCombinationKey> {
  19. private static final Logger logger = LoggerFactory.getLogger(DefinedCombinationKey.class);
  20. private Text firstKey;
  21. private IntWritable secondKey;
  22. public DefinedCombinationKey() {
  23. this.firstKey = new Text();
  24. this.secondKey = new IntWritable();
  25. }
  26. public Text getFirstKey() {
  27. return this.firstKey;
  28. }
  29. public void setFirstKey(Text firstKey) {
  30. this.firstKey = firstKey;
  31. }
  32. public IntWritable getSecondKey() {
  33. return this.secondKey;
  34. }
  35. public void setSecondKey(IntWritable secondKey) {
  36. this.secondKey = secondKey;
  37. }
  38. public void readFields(DataInput dateInput) throws IOException {
  39. // TODO Auto-generated method stub
  40. this.firstKey.readFields(dateInput);
  41. this.secondKey.readFields(dateInput);
  42. }
  43. public void write(DataOutput outPut) throws IOException {
  44. this.firstKey.write(outPut);
  45. this.secondKey.write(outPut);
  46. }
  47. /**
  48. * 自定义比较策略
  49. * 注意:该比较策略用于mapreduce的第一次默认排序,也就是发生在map阶段的sort小阶段,
  50. * 发生地点为环形缓冲区(可以通过io.sort.mb进行大小调整)
  51. */
  52. public int compareTo(DefinedCombinationKey definedCombinationKey) {
  53. logger.info("-------CombinationKey flag-------");
  54. return this.secondKey.compareTo(definedCombinationKey.getSecondKey()); } }

  1. 说明:
    1.在自定义组合键的时候,我们需要特别注意,一定要实现WritableComparable接口,并且实现compareTo方法的比较策略。这个用于mapreduce的第一次默认排序,也就是发生在map阶段的sort小阶段,发生地点为环形缓冲区(可以通过io.sort.mb进行大小调整),但是其对我们最终的二次排序结果是没有影响的。我们二次排序的最终结果是由我们的自定义比较器决定的。  
    2.在此示例代码中写了自定义组合键的compareTo对于score进行正序,在自定义比较器中对score进行倒序。用来分析MR的工作原理。

 

 F.打包运行。maven :mvn clean package

  1. hadoop jar mapReduceDemo-1.0-SNAPSHOT.jar com.m.mr.Main /person.csv /out

完~

数据及代码包见

代码示例已上传至GitHub,https://github.com/fzmeng/MapReduceExample

大数据系列之分布式计算批处理引擎MapReduce实践-排序的更多相关文章

  1. 大数据系列之分布式计算批处理引擎MapReduce实践

    关于MR的工作原理不做过多叙述,本文将对MapReduce的实例WordCount(单词计数程序)做实践,从而理解MapReduce的工作机制. WordCount: 1.应用场景,在大量文件中存储了 ...

  2. 大数据系列4:Yarn以及MapReduce 2

    系列文章: 大数据系列:一文初识Hdfs 大数据系列2:Hdfs的读写操作 大数据谢列3:Hdfs的HA实现 通过前文,我们对Hdfs的已经有了一定的了解,本文将继续之前的内容,介绍Yarn与Yarn ...

  3. 大数据系列之数据仓库Hive命令使用及JDBC连接

    Hive系列博文,持续更新~~~ 大数据系列之数据仓库Hive原理 大数据系列之数据仓库Hive安装 大数据系列之数据仓库Hive中分区Partition如何使用 大数据系列之数据仓库Hive命令使用 ...

  4. 大数据系列之并行计算引擎Spark介绍

    相关博文:大数据系列之并行计算引擎Spark部署及应用 Spark: Apache Spark 是专为大规模数据处理而设计的快速通用的计算引擎. Spark是UC Berkeley AMP lab ( ...

  5. 大数据系列之并行计算引擎Spark部署及应用

    相关博文: 大数据系列之并行计算引擎Spark介绍 之前介绍过关于Spark的程序运行模式有三种: 1.Local模式: 2.standalone(独立模式) 3.Yarn/mesos模式 本文将介绍 ...

  6. 批处理引擎MapReduce编程模型

    批处理引擎MapReduce编程模型 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. MapReduce是一个经典的分布式批处理计算引擎,被广泛应用于搜索引擎索引构建,大规模数据处理 ...

  7. 批处理引擎MapReduce内部原理

    批处理引擎MapReduce内部原理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MapReduce作业生命周期 MapReduce作业作为一种分布式应用程序,可直接运行在H ...

  8. 大数据系列之数据仓库Hive原理

    Hive系列博文,持续更新~~~ 大数据系列之数据仓库Hive原理 大数据系列之数据仓库Hive安装 大数据系列之数据仓库Hive中分区Partition如何使用 大数据系列之数据仓库Hive命令使用 ...

  9. 批处理引擎MapReduce应用案例

    批处理引擎MapReduce应用案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. MapReduce能够解决的问题有一个共同特点:任务可以被分解为多个子问题,且这些子问题相对独立 ...

随机推荐

  1. CentOS修改主机名字

    目录 查看hostnmae 修改hostname 远程别名/etc/hosts 查看hostnmae [root@centos ~]$ hostname centos 修改hostname [root ...

  2. Java线程池 与Lambda

    七.线程池.Lambda 1.1基本概念: ​ 线程池:其实就是一个容纳多个线程的容器,其中的线程可以反复使用,省去了频繁创建线程对象的操作,无需反复创建线程而消耗过多的资源. 1.2线程池的好处: ...

  3. MT【104】高斯函数找周期

    分析:$t(n)=n-[\frac{n}{2}]-[\frac{n}{3}]-[\frac{n}{6}]$的周期为6,故 $\sum\limits_{n=1}^{2014}(n-t(n))=\sum\ ...

  4. 再谈Scala集合

    集合!集合!一个现代语言平台上的程序员每天代码里用的最多的大概就是该语言上的集合类了,Scala的集合丰富而强大,至今无出其右者,所以这次再回过头再梳理一下. 本文原文出处:  还是先上张图吧,这是我 ...

  5. Java中public、private、protect对数据成员或成员函数的访问限制

    Java类中对数据成员.成员函数的访问限制修饰有:public.protect.private.friendly(包访问限制) public修饰的数据成员或成员函数是对所有用户开放的,所有用户可以直接 ...

  6. HGOI NOIP模拟4 题解

    NOIP国庆模拟赛Day5 题解 T1 马里奥 题目描述 马里奥将要参加 NOIP 了,他现在在一片大陆上,这个大陆上有着许多浮空岛,并且其中一座浮空岛上有一个传送门,马里奥想要到达传送门从而前往 N ...

  7. 踩坑记(1)——使用slf4j+logback记录日志

    刚开始的jar包版本如下,因为选择jar包版本不同导致的一些坑,踩过了就记录下来: <spring.version>3.1.0.RELEASE</spring.version> ...

  8. 【LOJ#10131】暗的锁链

    题目大意:给定一个 N 个点无向图的一棵生成树和另外 M 条边,第一次去掉生成树中的一条边,第二次去掉另外 M 条边中的一条边,求有多少种情况可以使得给定的无向图不连通. 题解:首先考虑该生成树,若新 ...

  9. 监控IIS的运行状态

    IIS经常出现假死的情况,具体什么时候会出现假死,我就不说了,今天我要写的是如何监控IIS的状态. 程序的功能是:如果IIS是为运行的状态,就重启IIS,如果IIS的连接数达到了设置的连接数,也重启I ...

  10. np.random.choice方法

    np.random.choice方法 觉得有用的话,欢迎一起讨论相互学习~Follow Me def choice(a, size=None, replace=True, p=None) 表示从a中随 ...