Giter Site home page Giter Site logo

jmagician / magician Goto Github PK

View Code? Open in Web Editor NEW
107.0 3.0 15.0 361 KB

Magician is a small HTTP service package based on Netty that makes it very easy to start an http service, and also supports WebSocket, using annotated configuration Handler, If you want to develop an http service with netty but find it cumbersome, then Magician may help you.

Home Page: https://magician-io.com

License: MIT License

Java 100.00%
nio network tcp udp java websocket magician http framework

magician's People

Contributors

yuyenews 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

magician's Issues

对于TCP部分代码的一些不成熟的建议

1,ByteBuffer.allocate 使用的是堆内内存,改为ByteBuffer.allocateDirect可以利用零拷贝提高性能

2,循环读取没必要全部读完,全部读完再处理有OOM的风险,可以读一部分就开始处理,具体的“拆包”逻辑可以交由具体基于TCP的协议解析器负责

3,

这个位置不会抛出异常,没必要try…catch

public TCPServer(EventGroup ioEventGroup, EventGroup workerEventGroup) {
        try {
            this.ioEventGroup = ioEventGroup;
            this.workerEventGroup = workerEventGroup;
            this.tcpServerConfig = new TCPServerConfig();
        } catch (Exception e) {
            log.error("打开serverSocketChannel,出现异常", e);
        }
    }

4,

EventGroup下面的所有EventRunner都公用一个线程池,建议中间这几个都删了,改为forkjoin线程池直接提交吧,也自带工作窃取

5,TCP server读,写,连接都在单线程中,瓶颈较大,可以尝试改为连接绑定某一线程单线读写,单线程做连接处理

这一段可以加入作为while的条件

if(ioEventGroup.getThreadPool().isShutdown()){
                logger.error("ioEventGroup里的线程池关闭了,所以Selector也停止了");
                selector.close();
                serverSocketChannel.close();
                return;
            }

6,TCPServerMonitorTask#run()最后一行

selector.wakeup();

我认为没有意义,这个操作是外部线程触发使得当前selector持有线程从select的阻塞 中唤醒,自己调用时已经是唤醒状态
7,TCP server是否与协议解析绑定太深?
8,EventLoop是个很好的模型,可以参考一些EventLoop的实现

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.