是否可以线程池IMAP连接? [英] Is it possible to thread pool IMAP connections?

查看:121
本文介绍了是否可以线程池IMAP连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,IMAP要求每个用户都有一个连接.我正在编写一个IMAP客户端(目前仅为gmail),一次可支持许多(100s,1000s或10000s +)用户.显然,减少开放连接的数量将是巨大的.我想知道是否可以在我这边使用线程池通过IMAP连接到gmail,或者IMAP协议根本不支持这种连接.

From what I understand IMAP requires a connection per each user. I'm writing an IMAP client (currently just gmail) that supports many (100s, 1000s maybe 10000s+) users at a time. Obviously cutting down the number of open connections would be great. I'm wondering if it's possible to use thread pooling on my side to connect to gmail via IMAP or if that simply isn't supported by the IMAP protocol.

推荐答案

IMAP通常使用基于TCP/IP的SSL.而且,每个IMAP客户端连接都需要维护一个TCP/IP连接,这意味着将有许多同时打开的连接.

IMAP typically uses SSL over TCP/IP. And a TCP/IP connection will need to be maintained per IMAP client connection, meaning that there will be many simultaneous open connections.

可以在非线程(单线程)实现中轻松维护这些多个同时连接,而不会影响TCP连接的状态.每个IMAP TCP/IP连接都必须具有某种流概念,并将所有流存储在使用TCP/IP五元组(或socketFd)作为容器的容器(例如c ++ STL映射)中.钥匙.对于收到的每个数据包,请查找流并相应地处理该包.这种方法不会影响TCP或IMAP连接.

These multiple simultaneous connections can easily be maintained in a non-threaded (single thread) implementation without affecting the state of the TCP connections. You'll have to have some sort of a flow concept per IMAP TCP/IP connection, and store all of the flows in a container (a c++ STL map for instance) using the TCP/IP five-tuple (or socketFd) as a key. For each data packet received, lookup the flow and handle the packet accordingly. There is nothing about this approach that will affect the TCP nor IMAP connections.

考虑到这将在单线程环境中起作用,添加线程池只会增加应用程序的吞吐量,因为您可以同时处理多个流的数据包(假设它是多核CPU),需要确保2个线程不同时处理同一数据流的数据包,这可能导致数据包处理混乱.一种方法可能是每个线程有一组流,可能使用IP池或类似的方法.

Considering that this will work in a single-thread environment, adding a thread pool will only increase the throughput of the application, since you can handle data packets for several flows simultaneously (assuming its a multi-core CPU) You will just need to make sure that 2 threads dont handle data packets for the same flow at the same time, which could cause the packets to be handled out of order. An approach could be to have a group of flows per thread, maybe using IP pools or something similar.

这篇关于是否可以线程池IMAP连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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