Giter Site home page Giter Site logo

Comments (11)

jiongjionger avatar jiongjionger commented on August 22, 2024

正因为写入时做了快照拷贝,写入完后直接让指针指向新的数组对象,保证了线程安全。用于保存实体和区块的数组大小并不大,额外内存占用问题应该不显著。说实话,由于所有代码都在一个patch里面,我也只是粗略的看了一遍。个人觉得一些写为主的还是使用Collections.synchronizedList来做锁同步更好一点。

from hose.

andylizi avatar andylizi commented on August 22, 2024

虽然大小不大, 但是大量的写入, 每次都复制一份的消耗还是很可怕的. JVM的垃圾回收本来就..

from hose.

softpak avatar softpak commented on August 22, 2024

記憶體使用方面可以用jmap來監視,就我檢查過是沒問題的,gc正常運作,記憶體消耗量差異也不大,大約是spigot的120~150%。會用copyonwrite主要是因為出現concurrent exception,加上本身多數的型別都是list,為了減少修改的部分就只能先這樣,否則我都會改成queue。

另外jiongjionger提到synchronizedList的問題,經實際使用反而會導致thread blocked,所以不用,雖然concurrent的集合裡很多也是用synchronized來實作,但就是不會有問題。

最後我是臺灣人。

from hose.

andylizi avatar andylizi commented on August 22, 2024

是否有可能使用Amino并发框架(github)

from hose.

softpak avatar softpak commented on August 22, 2024

Lockfreelist看起來是個好用的東西,感謝提供lib,我會試試看的。

from hose.

andylizi avatar andylizi commented on August 22, 2024

我昨天测试了一下LockFreeList和LockFreeVector(说明中,LockFreeList基于链表,相当于LinkedList,LockFreeVector基于原子数组,相当于ArrayList),速度和占用内存还是有点大了..我正在试着自己用原子数组实现ConcurrentList

from hose.

jiongjionger avatar jiongjionger commented on August 22, 2024

无锁实现在竞争激烈的时候开销非常非常大,这个最好做对比测试再决定用哪种。

from hose.

softpak avatar softpak commented on August 22, 2024

其實我比較偏向用google或java本身的lib,畢竟相比之下更為嚴謹且集大成。

from hose.

andylizi avatar andylizi commented on August 22, 2024

前提是如果有. 我找了半天也就找到一个Amino了,并且在百度上的介绍也不多
很奇怪,apache-commons和guava几乎什么功能都集成了,但在并发方面一个也没有
难道真的这么难?

from hose.

softpak avatar softpak commented on August 22, 2024

併發的部分Java本身就很多了,
我列個常見的對照表:

 1. CopyOnWriteArrayList   (Thread safe arrayList)

 2. ConcurrentLinkedDeque  (Thread safe LinkedList)

 3. ConcurrentHashMap      (Thread safe HashMap)

 4. CopyOnWriteArraySet    (Thread safe HashSet)

 5. ConcurrentSkipListMap  (Thread Safe TreeMap)

 6. ConcurrentSkipListSet  (Thread Safe TreeSet)

 7. ConcurrentLinkedQueue  (Thread safe Priority Queue)

這些也是我優先使用的。
另外MC自己本身特化的MAP如IntHashMap我個人是改成了ConcurrentHashMap,
老實說效能沒差異,
反而避免了很多問題。

from hose.

softpak avatar softpak commented on August 22, 2024

主要是因為MC都用list,而list的大小約在1萬以下,如果使用Vector還要在執行完轉成List,否則插件跟指令會無法運作,因為怕轉換過程被插入或什麼的會導致資料不全,所以list的部分並沒有打算再修改。說個題外話,之前試著將entityslice改成vector,要改到了大約30多個檔案的宣告,而程式變得反而容易出錯,追蹤之下,最後變成要去修改官方的server.jar,光這點侵權就不適合了。但mojang確實逐步進步中,是可以期待這部分的改善的。

from hose.

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.