2. Mobile Push Notification Service
● Google - GCM (Google Cloud Message), C2DM
● Apple - APNS (Apple Push Notification Service)
● MS - MPNS (Microsoft Push Notification Service)
● SKT - Smart Push(AlwaysOn Management framework)
● 기타...
13년 1월 28일 월요일
3. Android Push Notification Service
● GCM (Google Cloud Message)
- Getting Started :
http://developer.android.com/google/gcm/gs.html
● Private Push Service
- 각 서비스/업체별로 구현한 Push Service
13년 1월 28일 월요일
4. Naver Npush
SKT AOM
Kakatok
Facebook Messenger
Viber
NateOn
기타
이미지 출처 : http://helloworld.naver.com/helloworld/1846
13년 1월 28일 월요일
5. Why Private Push Service ?
● C2DM시절 Push의 낮은 신뢰도 (속도, 도달률)
● Google의 전송량 제한
● Android 2.2 이상 ( Froyo )
● 구글 계정으로 로그인해야 사용 가능
● 자체 Customizable Business Rules 구현 필요
13년 1월 28일 월요일
6. PUSH 구현 방식 - Push & Pull
● Push - 지속적인 연결 유지
Server -> Client
● Pull - 지속적인 Polling으로 데이타 갱신 ( 카카오톡)
Client -> Server
● 차이점
- 정보의 주도권
- 배터리, 패킷 소모량
13년 1월 28일 월요일
7. Push Service 구현 = Server <- (protocol) -> Client
● MQTT
● XMPP
● HTTP
● Custom Protocol
MQTT = MQ Telemetry Transport
XMPP = Extensible Messaging and Presence Protocol
HTTP = HyperText Transfer Protocol
13년 1월 28일 월요일
8. XMPP (5222)
* XML 기반
* 원래 이름은 Jabber
* Jabber 오픈소스 커뮤니티 1999년
* 국제 인터넷 표준화 기구 - 개방형 표준
* IM, 채팅
* Google Talk, Google App Engine 제공
* BOSH : JavaScript, Firewall
BOSH : Bidirectional-streams Over Synchronous HTTP
13년 1월 28일 월요일
9. XMPP 메시지 형태
Stream
<stream:stream from="[server]" id="[unique ID over conversation]"
xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
Message
<message from="sendinguser@somedomain"
to="recipient@somedomain" xml:lang='en'>
<body>
Body of message
</body>
</message>
http://www.ibm.com/developerworks/kr/xml/tutorials/x-realtimeXMPPtut/section3.html
13년 1월 28일 월요일
10. MQTT (1883)
* IBM과 Eurotech(Arcom)에 의해 1999년 최초 개발
* 센서, 원격 검침 영역 , 모바일기기, 아두이노
Low bandwidth, High latency, Unreliable, High cost
* Clinet lib: C 버전 30Kb, Java 버전 100Kb 내외
* Publish/Subscribe, QoS 제공 (0, 1, 2)
* Openly published with a royalty-free license
* minimal 2byte, 가변길이
13년 1월 28일 월요일
11. MQTT 메시지 형태
Reserved - Reserved
CONNECT - Client request to connect to Server
CONNACK - Connect Acknowledgment
PUBLISH - Publish message
PUBACK - Publish Acknowledgment
PUBREC - Publish Received (assured delivery part 1)
PUBREL - Publish Release (assured delivery part 2)
PUBCOMP - Publish Complete (assured delivery part 3)
SUBSCRIBE - Client Subscribe request
SUBACK - Subscribe Acknowledgment
UNSUBSCRIBE - Client Unsubscribe request
UNSUBACK - Unsubscribe Acknowledgment
PINGREQ - PING Request
PINGRESP - PING Response
DISCONNECT - Client is Disconnecting
Reserved - Reserved
MQTT Spec v3.1 :
http://www.ibm.com/developerworks/webservices/library/ws-mqtt/index.html
http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/MQTT_V3.1_Protocol_Specific.pdf
13년 1월 28일 월요일
21. Mosquitto - 1차 테스트
* Console & Mosquitto Command
* Java Client Library
OK !
* Mosquitto Java Client
* Akka + IBM Paho Client
* Python Client Libarry
* python-mosquitto
* MQTT-for-Twisted-Python
* nyamuk
Akka ( http://akka.io )
- Build powerful concurrent & distributed applications more easily. on the JVM
13년 1월 28일 월요일
22. Mosquitto - 2차 성능 테스트
* 서버 1대
* CentOS 5.5
* Mosquitto 1 프로세스
6500
* 클라이언트 6500
* 맥북 프로 2대 + iMac 1대
* 각 6500개 Python Client
* ipTime 공유기 n700 공유기 6500
mosquitto
console
broker
13년 1월 28일 월요일
23. Mosquitto - 2차 결과
- 약 2만개 Python MQTT Client 안정적 접속 (2.5일간 유지)
- CPU : 단일 코어 사용
- 메모리는 Client 수와 상관없이 일정하게 유지
- 연결 유지를 위한 Ping Req/Res의 트래픽 : 별도 전용선
- Publish Time 5초 ~ 6초 ( 이유는 ipTime 공유기의 한계 - 속도 지연)
OK !
13년 1월 28일 월요일
24. 알게 된 것 1 : 별도의 전용 Line을 통한 서비스
알게 된 것 2 : Default FD <= 1024
13년 1월 28일 월요일
25. import mosquitto
def on_connect(mosq, obj, rc):
print("rc: "+str(rc))
def on_message(mosq, obj, msg):
print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
def on_publish(mosq, obj, mid):
print("mid: "+str(mid))
def on_subscribe(mosq, obj, mid, granted_qos):
print("Subscribed: "+str(mid)+" "+str(granted_qos))
def on_log(mosq, obj, level, string):
print(string)
# If you want to use a specific client id, use
# mqttc = mosquitto.Mosquitto("client-id")
# but note that the client id must be unique on the broker. Leaving the
client
# id parameter empty will generate a random id for you.
mqttc = mosquitto.Mosquitto()
mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe
# Uncomment to enable debug messages
#mqttc.on_log = on_log
mqttc.connect("test.mosquitto.org", 1883, 60)
mqttc.subscribe("$SYS/#", 0)
rc = 0
while rc == 0:
rc = mqttc.loop()
print("rc: "+str(rc))
https://bitbucket.org/oojah/mosquitto/src/tip/lib/python/sub.py
13년 1월 28일 월요일
26. Default 1024
Error
filedescriptor out of range in select()
13년 1월 28일 월요일
28. Python IO
* select
- The first three arguments are sequences of
‘waitable objects’: either integers representing
file descriptors
* kqueue
- kernel event notification mechanism
* kevent
- Returns a kernel event object
* poll
- better scalability for network servers
that service many, many clients
at the same time
* epoll
- Returns an edge polling object, which can be used as Edge or
Level Triggered interface for I/O events
13년 1월 28일 월요일
29. MQTT-For-Twisted-Python
https://github.com/adamvr/MQTT-For-Twisted-Python/blob/master/MQTT.py
MQTT4PythonTwistedDemo
https://code.google.com/p/beaglebone-iot/wiki/MQTT4PythonTwistedDemo
from twisted.internet import kqreactor
kqreactor.install()
....
if __name__ == '__main__':
mqttMessageBuffer = []
clientCountRange = range(1, 1200)
for r in clientCountRange:
try:
mqttFactory = MQTTListenerFactory()
reactor.connectTCP("192.168.10.32", 1883, mqttFactory)
except:
log.msg("except " + sys.exec_info())
reactor.run()
13년 1월 28일 월요일
30. What is Twisted?
Twisted is an event-driven networking engine written in Python
from twisted.internet import protocol, reactor
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr): twisted.web import server, resource
from
return Echo() from twisted.internet import reactor
class HelloResource(resource.Resource):
reactor.listenTCP(1234, EchoFactory())
isLeaf = True
reactor.run() numberRequests = 0
def render_GET(self, request):
self.numberRequests += 1
request.setHeader("content-type", "text/plain")
return "I am request #" +
str(self.numberRequests) + "n"
reactor.listenTCP(8080, server.Site(HelloResource()))
reactor.run()
13년 1월 28일 월요일
31. Twisted Document - Reactor
Reactor Overview
1. Reactor Basics
2. Using the reactor object
This HOWTO introduces the Twisted reactor, describes the basics of the reactor and links to the various reactor interfaces.
Reactor Basics
The reactor is the core of the event loop within Twisted -- the loop which drives applications using Twisted. The event loop is a programming construct that waits for
and dispatches events or messages in a program. It works by calling some internal or external "event provider", which generally blocks until an event has arrived,
and then calls the relevant event handler ("dispatches the event"). The reactor provides basic interfaces to a number of services, including network
communications, threading, and event dispatching.
Choosing a Reactor and GUI Toolkit Integration
1. Overview
2. Reactor Functionality
3. General Purpose Reactors
◦ Select()-based Reactor
4. Platform-Specific Reactors
◦ Poll-based Reactor
◦ KQueue
◦ WaitForMultipleObjects (WFMO) for Win32
◦ Input/Output Completion Port (IOCP) for Win32
◦ Epoll-based Reactor
5. GUI Integration Reactors
◦ GTK+
◦ wxPython
◦ CoreFoundation
6. Non-Reactor GUI Integration
◦ Tkinter
◦ PyUI
13년 1월 28일 월요일
32. Reactor Pattern?
The reactor design pattern is an event handling pattern for handling service
requests delivered concurrently to a service handler by one or more inputs.
The service handler then demultiplexes the incoming requests and dispatches
them synchronously to the associated request handlers
All reactor systems are single threaded by definition, but can exist in a
multithreaded environment.
C - libevent
C++ - POCO C++ Libraries
Java - Apache MINA, JBoss Netty, Apache Cocoon, Disruptor
JavaScript - Node.js
Perl - POE
Python - Twisted
Ruby - EventMachine
http://en.wikipedia.org/wiki/Reactor_pattern
13년 1월 28일 월요일
33. POSA 2
Patterns for Concurrent and Networked Objects
이미지 출처 : http://www.cs.wustl.edu/~schmidt/POSA/POSA2/
13년 1월 28일 월요일
34. Opps !
이미지 출처 : http://goo.gl/HUiFZ
13년 1월 28일 월요일
35. 만드는 이유?
* 기업 => Push 마케팅 Tool
* 기업 기간계 시스템 연동 : 보험, 증권, 은행, 쇼핑몰
=> SMS/MMS = 비용
* 기업 자신들의 모바일 앱 고객 분석
13년 1월 28일 월요일
36. 기업 개발 부서 반응
* 이런 걸 왜 사?
* 내가 이틀이면 만들겠다 = 자체 개발? => 몇 달 뒤 전화 옴
* 발송만 보면 이틀이 아니라 몇 시간 내에 가능 => 맞는 말
* 그러나 기업 자체 개발 인력 부족, 자체 문제 및 요구사항
* History : 메일 = PUSH
13년 1월 28일 월요일
37. 헉 !!!
http://count.ly/
https://github.com/Countly node.js, mongodb, nginx
https://github.com/isaacs/node-supervisor
http:/
http:/
/countly.firejune.io/login
/goo.gl/U63L1
supervisor, python
13년 1월 28일 월요일
38. 정리
* Private Push Server 구축은 어렵지 않게 시작 할 수 있다.
* 이를 구축하는데 MQTT 좋은 선택
* Python IO Server/Client => twisted 시작
* 국내 Push 독보적인 솔루션 없음 => 메일 시장 History 반복
13년 1월 28일 월요일
39. 최종 보스
이미지 출처 : http://goo.gl/NF18A
13년 1월 28일 월요일