GithubHelp home page GithubHelp logo

Comments (11)

qiujiayu avatar qiujiayu commented on August 26, 2024

请问你用的是哪个版本。

这个问题在使用JSON 序列化时也遇到了,现在的解决办法不是很优雅。
请参考:https://github.com/qiujiayu/AutoLoadCache/blob/master/src/main/java/com/jarvis/cache/MagicHandler.java

中 public Object magic() throws Throwable 方法内的:“为了解决使用JSON反序列化时,缓存数据类型不正确问题” 注释内容。加了这些代码后,使用Magic模式时,返回值不允许有多泛型再套泛型的情况。

为了更好复现问题,是否可以把你的 protobuf序列化实现提上来?

from autoloadcache.

realoldroot avatar realoldroot commented on August 26, 2024

#68
Magic模式下ProtoBufSerializer方法public CacheWrapper<Object> deserialize(byte[] bytes, Type returnType) throws Exception第二个参数是缓存方法的返回类型,是List,这时反序列化就出错了。

from autoloadcache.

qiujiayu avatar qiujiayu commented on August 26, 2024

我分析了一下你的代码,主要问题还是因为序列化方式和返序列化方式不一样造成的,已经提交一版本了,你先测一测。

from autoloadcache.

realoldroot avatar realoldroot commented on August 26, 2024

经测试可以成功反序列化了。还是对反射的学习不够多,十分感谢。

from autoloadcache.

qiujiayu avatar qiujiayu commented on August 26, 2024

我个人觉得代码还有很大的优化空间:比如:writePool 和 readPool 可能造成内存的浪费,如果有几个大对象,那么会一直占用非常大的内存。

from autoloadcache.

realoldroot avatar realoldroot commented on August 26, 2024

当时的想法是为了在序列化的时候减少对象的创建,减少GC,就使用对象池,根据业务需求固定了WriteByteBuf的长度,在序列化消息的时候可以反复使用这块内存。
写池目前最大内存会达到8*1m左右。
你说的大对象指的是对象池里的对象吗。

from autoloadcache.

qiujiayu avatar qiujiayu commented on August 26, 2024

是的

from autoloadcache.

qiujiayu avatar qiujiayu commented on August 26, 2024

我又改了一版,你再测测。

from autoloadcache.

realoldroot avatar realoldroot commented on August 26, 2024

测试可以使用:+1:
另外我想问一下序列化对象池这一块,有什么优化思路吗,比如说动态扩容?
或者说对象池的使用意义是否大于频繁的实例化而带来的GC。

from autoloadcache.

qiujiayu avatar qiujiayu commented on August 26, 2024

�弊大于利,两个理由:1. 使用对象池会增加锁同步问题 ; 2. 大对象造成内存不可回收问题;
内存这块可以尝试使用堆外内存,来减少GC;尽量要达到不动态扩容:

   public byte[] serialize(CacheWrapper<Object> obj) throws Exception {
        Object cacheObj = obj.getCacheObject();
        byte[] data = null;
        if (cacheObj instanceof Message) {
            Message message = (Message) cacheObj;
            data = message.toByteArray();
        } else if (cacheObj != null) {
            data = MAPPER.writeValueAsBytes(cacheObj);
        }
        val byteBuf = new WriteByteBuf(12 + data.length);
        byteBuf.resetIndex();
        byteBuf.writeInt(obj.getExpire());
        byteBuf.writeLong(obj.getLastLoadTime());
        byteBuf.writeBytes(data);
        val bytes = byteBuf.readableBytes();
        writePool.returnObject(byteBuf);
        return bytes;
    }

from autoloadcache.

realoldroot avatar realoldroot commented on August 26, 2024

谢谢:smile:

from autoloadcache.

Related Issues (20)

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.