Giter Club home page Giter Club logo

doraemon's Introduction

doraemon's People

Contributors

hupengfei123 avatar modouxiansheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doraemon's Issues

关于Annotation Processor动态生成方法的问题

我是从你的博客搜过来的, 关于TreeMaker的使用相关的博客很少, 你写的那篇很详细, 受益匪浅.
现在我在做一个需求, 计划在编译期为目标类动态添加方法, 但是这个目标类是个空类, 在调用 TreeMaker.NewClass 来调用构造器实例化对象的时候, 会一直报找不到符号
image

我试过各种方式, 都编译失败, 我想请问一下你这边是如何处理的, 或者有没有相关文档能够参考

附上生成代码的关键部分代码:
image

抱歉由于公司对 github 有进行代码扫描, 不能在这里贴出所有的代码, 如果需要, 可以线下沟通, Thanks! : )

redis热点key咨询

您好,我想咨询您关于Redis 热点key的问题;
对于热点key的处理,应该什么时候去进行处理呢。是当某个redis的节点的那些性能指标出现下降的时候,在去做热点key的统计,然后在做处理吗?
1.热点key的处理时机?
2.判断处理热点key,应该考虑什么性能指标?

项目启动

项目pull 下来 启动 rpc这个项目启动不起来 找不到 :common 这个模块

FileCompress 压缩测试 Pipe 并不是最快的方式

废话就不多说了,直接上代码了。

`package com.rayn.commons.io;

import org.apache.commons.lang3.time.StopWatch;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.Pipe;
import java.nio.channels.WritableByteChannel;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**

  • @author Ryan

  • @Date 2019/11/16 11:51
    */
    public class IOStreamTurningExample {

    public IOStreamTurningExample() {
    }

    /**

    • Native IO Stream

    • @param srcFile

    • @param destFile
      */
      public static void nativeStreamWriterFile(File srcFile, File destFile) {

      final StopWatch stopWatch = new StopWatch();
      stopWatch.start();
      try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(destFile))) {
      try (final FileInputStream fileInputStream = new FileInputStream(srcFile)) {
      zipOutputStream.putNextEntry(new ZipEntry(destFile.getName()));
      byte[] b = new byte[1024 * 1024 * 5];
      int readSize = 0;
      while ((readSize = fileInputStream.read(b)) > 0) {
      zipOutputStream.write(b, 0, readSize);
      }
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      }
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }

      stopWatch.stop();
      printInfo("nativeStreamWriterFile", stopWatch);
      }

    /**

    • Use Buffer IO Stream

    • @param srcFile

    • @param destFile
      */
      public static void bufferStreamWriterFile(File srcFile, File destFile) {
      final StopWatch stopWatch = new StopWatch();
      stopWatch.start();
      try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(destFile));
      final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(zipOutputStream)) {

       try (final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(srcFile))) {
           zipOutputStream.putNextEntry(new ZipEntry(destFile.getName()));
           byte[] b = new byte[1024 * 1024 * 5];
           int readSize = 0;
           while ((readSize = bufferedInputStream.read(b)) != -1) {
               bufferedOutputStream.write(b, 0, readSize);
           }
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }
      

      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }

      stopWatch.stop();
      printInfo("bufferStreamWriterFile", stopWatch);
      }

    /**

    • Use Channel IO Stream

    • @param srcFile

    • @param destFile
      */
      public static void channelStreamWriterFile(File srcFile, File destFile) {

      final long fileSize = srcFile.length();

      final StopWatch stopWatch = new StopWatch();
      stopWatch.start();
      try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(destFile));
      final WritableByteChannel writableByteChannel = Channels.newChannel(zipOutputStream)) {

       try (final FileChannel fileChannel = new FileInputStream(srcFile).getChannel()) {
           zipOutputStream.putNextEntry(new ZipEntry(destFile.getName()));
      
           fileChannel.transferTo(0, fileSize, writableByteChannel);
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }
      

      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }

      stopWatch.stop();
      printInfo("channelStreamWriterFile", stopWatch);
      }

    /**

    • @param srcFile

    • @param destFile
      */
      public static void mappedStreamWriterFile(File srcFile, File destFile) {
      final long fileSize = srcFile.length();

      final StopWatch stopWatch = new StopWatch();
      stopWatch.start();
      try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(destFile));
      final WritableByteChannel writableByteChannel = Channels.newChannel(zipOutputStream)) {

       zipOutputStream.putNextEntry(new ZipEntry(destFile.getName()));
      
       try (final FileChannel fileChannel = new RandomAccessFile(srcFile, "r").getChannel()) {
           final MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
           writableByteChannel.write(mappedByteBuffer);
       }
      

      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }

      stopWatch.stop();
      printInfo("mappedStreamWriterFile", stopWatch);
      }

    /**
    *
    */
    public static void pipeStreamWriterFile(File srcFile, File destFile) {
    final long fileSize = srcFile.length();

     final StopWatch stopWatch = new StopWatch();
     stopWatch.start();
     try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destFile));
          final WritableByteChannel writableByteChannel = Channels.newChannel(zos)) {
    
         zos.putNextEntry(new ZipEntry(destFile.getName()));
    
         final Pipe pipe = Pipe.open();
    
         CompletableFuture.runAsync(() -> {
             try (ZipOutputStream zipOutputStream1 = new ZipOutputStream(Channels.newOutputStream(pipe.sink()));
                  final WritableByteChannel writableByteChannel1 = Channels.newChannel(zipOutputStream1)) {
    
                 zipOutputStream1.putNextEntry(new ZipEntry(destFile.getName()));
    
                 final FileChannel destFileChannel = new FileInputStream(srcFile).getChannel();
                 destFileChannel.transferTo(0, fileSize, writableByteChannel1);
                 destFileChannel.close();
             } catch (FileNotFoundException e) {
                 e.printStackTrace();
             } catch (IOException e) {
                 e.printStackTrace();
             }
         });
    
         final Pipe.SourceChannel sourceChannel = pipe.source();
         final ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024 * 10);
    
         while (sourceChannel.read(buffer) >= 0) {
             buffer.flip();
             writableByteChannel.write(buffer);
             buffer.clear();
         }
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     } catch (IOException e) {
         e.printStackTrace();
     }
    
     stopWatch.stop();
     printInfo("pipeStreamWriterFile", stopWatch);
    

    }

    private static void printInfo(String method, StopWatch stopWatch) {

     System.out.println("\n\n" + method + ":");
     System.out.println("Start Time : " + stopWatch.getStartTime());
     System.out.println("Duration Time : " + stopWatch.toString());
    

    }

    public static void main(String[] args) {

     File src_file = new File("D:/test/bigfile.mp4");
    
     File dest_file = new File("D:/test/bigfile.zip");
    
    
     nativeStreamWriterFile(src_file, dest_file);
    
     bufferStreamWriterFile(src_file, dest_file);
    
     channelStreamWriterFile(src_file, dest_file);
    
     mappedStreamWriterFile(src_file, dest_file);
    
     pipeStreamWriterFile(src_file, dest_file);
    
     try {
         TimeUnit.SECONDS.sleep(100);
     } catch (InterruptedException e) {
         e.printStackTrace();
     }
    

    }
    }
    `

唯一与作者不同之处在于 fileInputStream.read(new byte[1024 * 1024 * 5)

测试 srcFile 大小为:1.13 G 的电影。

测试结果

nativeStreamWriterFile:
Start Time : 1573884268436
Duration Time : 0:00:52.334

bufferStreamWriterFile:
Start Time : 1573884320778
Duration Time : 0:00:51.496

channelStreamWriterFile:
Start Time : 1573884372275
Duration Time : 0:00:52.157

mappedStreamWriterFile:
Start Time : 1573884424432
Duration Time : 0:00:51.618

pipeStreamWriterFile:
Start Time : 1573884476051
Duration Time : 0:01:19.865

请问,是我哪里的姿势不对吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.