如何CPU密集型正在打开一个套接字 [英] How cpu intensive is opening a socket

查看:85
本文介绍了如何CPU密集型正在打开一个套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个服务器相当频繁通信的应用程序。我有套接字创建一个单独的类进行,以确保创建工作就只进行一次。然而,这是一个Android应用程序,我可以永远保证code时被破坏应用程序将被执行的清理。因此,我目前开放每次我用它时关闭套接字。

So, I have an application that communicates with a server quite frequently. I have the Socket creation done in a singleton class, to ensure that the work to create it is only done once. However, this is an Android application, and I can never guarantee that the code that cleans up when the application is destroyed will be executed. Therefore, I am currently opening and closing the socket every time I use it.

我不知道如何CPU密集型这虽然,任何人都可以提供一些线索?

I have no idea how cpu intensive this is though, can anyone shed some light?

推荐答案

@providence,如果它是打开/关闭每次插座使用它,从CPU的工作负载点的一个单独的应用程序,这不是我想过分担心。如果你有保持套接字打开的选项,它们实际上可能是一个更好的事情。移动数据连接选项股份公司GPRS,EDGE,3G-UMTS等,具有优化内置,其中放弃无线网络带宽在不使用时,甚至可能进入低功耗状态。只有当不存在要被接收或发送的一些数据,并在电话回来它的操作功率模式,并分配无线资源,以插座。所有这一切你休眠插座正在做的是占用一些内存。

@providence, if it is a single application which opens/closes the sockets everytime it is used, from a CPU workload standpoint, it is not something I'd worry too much about. If you have an option of keeping the socket open, they might actually be a better thing to do. Mobile data connection options s.a. GPRS, EDGE, 3G-UMTS etc., have optimizations built-in, which relinquish wireless network bandwidth when not in use, and may even enter low-power state. Only when there is some data to be received or sent, does the phone come back to it's operating-power mode, and allocated wireless resources to the socket. All that your dormant socket is doing is consuming some memory.

PS>有在做Android上的网络编程(直接在插座级),其中很大一部分是我写的没有第一手的经验是基于无线网络技术知识,和一般的Unix套接字通讯基本面: - )

PS> Having no first hand experience in doing network programming (directly at socket level) on Android, much of what I wrote is based on knowledge of wireless network technology, and general unix socket communication fundamentals :-).

只有当你喜欢我的答案,并发现它有用随意投上一票。

Only if you like my answer, and find it useful feel free to vote it up.

这篇关于如何CPU密集型正在打开一个套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆